I have an SQL procedure that calls the command shell to write an SQL dump to a file. Take this redacted file for example:
VALUES(
@SomeVar
,1
)
The procedure calls:
echo VALUES(>> C:\somefile.sql
echo @SomeVar>> C:\somefile.sql
echo ,1>> C:\somefile.sql
echo )>> C:\somefile.sql
This works fine, except for the ,1
line. If you run echo ,1>> C:\somefile.sql
in CMD, you will see that C:\somefile.sql only contains ,
My theory is that echo
thinks it can accept more than 1 parameter.
If you modify the command to echo ,1blah>> C:\somefile.sql
, it works perfectly.
I could modify my procedure to check if the line contains a ,
followed by a number, not followed by anything, and prepend ^
to the number to escape it. This is a bit of a pain though.
Also, echo 1>> C:\somefile.sql
writes Echo is ON
Is there a way to echo
a literal string in CMD? Enclosing the string in " "
outputs the "
marks. Or is there any other solution you can think of?