|
Answer» Hello Everyone,
I am facing one problem while writing an automation batch program.
I think MS command prompt(cmd.exe/command.exe) allows maximum of 127 characters in a single line of command. I am building some commands dynamically in a batch file and executing it. This batch file runs successfully if number of characters in the dynamic command are <= 127 and fails otherwise. Following is the test scenario:
C:\COBCF3~1>sed -e "s/([Ss][Ee][Ll][Ee][Cc][ \t]*[Ss][Uu][Mm](\(.*\))[ \t]*[Ff][Rr][Oo][Mm][ \t]*[Dd][Uu][Aa][Ll])/Sum(\1)/g" test1.sql
CREATE or replace VIEW vwBrowse1x402x187 AS SELECT(SELECT PartyDetails.Party FROM Parties INNER Join PartyDetails ON Parties.PartyDetailID = PartyDetails.PartyDetailID WHERE Parties.PartyID = PatentMasters.ClientDivision) Division,Sum(PatentExpenses.Amount) "YTD Total" FROM PatentExpenses INNER JOIN PatentMasters ON PatentExpenses.PatentMasterID = PatentMasters.PatentMasterID where(DATENAME('Year',PatentExpenses.ExpenseDate) = DATENAME('Year',SYSDATE)) GROUP BY PatentMasters.ClientDivision;
C:\COBCF3~1>rem above command is having 127 characters in it and EXECUTED successfully
C:\COBCF3~1>rem To make command exceed 127 characters, I will increase the characters in the command by increasing the INPUT file name to sed command(dos version of sed)
C:\COBCF3~1>ren test1.sql test12.sql
C:\COBCF3~1>sed -e "s/([Ss][Ee][Ll][Ee][Cc][ \t]*[Ss][Uu][Mm](\(.*\))[ \t]*[Ff][Rr][Oo][Mm][ \t]*[Dd][Uu][Aa][Ll])/Sum(\1)/g" test12.sql The system cannot execute the specified program.
I know that there is concept of command continuation character in many interpreted command prompts like Unix (\) but I am not aware if such things exist in MS Command prompt as "\" doesn't work for me.
Any help will be highly appreciated.
Thanks in advance.
DG It's true that early versions of DOS had a 127 byte character limitation. It's equally true there is no continuation character in DOS...just keep typing until you overrun the buffer.
Confused though. I was under the impression that SED was an editor. Are you trying to execute the SQL? Most database programs allow sql statements to come from external files where there is no character limitation.
Let us know. Thanks for your reply. I am sorry to confuse you "sed" is string manipulation utility command for MS Dos... its exactly similar to "sed" command in Unix. The SQL scripts you are seeing is the output of the SED command which takes one input file test1.sql and is nothing to do with this command. The content of input file test1.sql could be any text. test1.sql is one SQL Server file GENERATED using some automated script and I need to do some string manipulation before executing that to its target database. Pls let me know if you can think of any solution.
Thanks for your valuble time and help.
After reading about SED, AWK is a walk in the PARK I couldn't find anything to help you. You might try redirecting a text file with all the parameters into SED but there is no guarantee. Only programs written to accept input from STDIN will accept redirected input.
Good luck. Thanks for the try :-) Yes, I found alternative to handle this scenario using sed script file. SED can accept commands from a script file where there is no such limit on the number of characters in single command line.
|