1.

Solve : Creating separate error files in Batch?

Answer»

I need to create error FILES from running a batch file for each of the command used.I need the error file NAME same as that of the "*.sql" name but with extn "*.err".
How do I proceed with this?
This is the existing code

FOR %%i IN ("*.sql") DO (
echo :r "%%i" >> run.txt)

I need to send the errors that arise on running the run.txt into the appropriate filesnames from where the error has generated.
Not really understanding. As written, you will end up with run.txt looking something like this:

:r 1.sql
:r 2.sql
:r 3.sql

Please explain what result your looking for. Are you looking to pass a error file label as a command line argument?, redirect output to an error file?, or use the stderr data stream?.



Note: run.txt is not an executable file.


I basically want to create batch files to run sql scripts from command promt using sqlcmd. The inputs to the sqlcmd will be from a text file.Whenever an error is ENCOUNTERED on running the script, the errors alone should be logged in the error file which is in the executed script name extn alone as .err.

The input text file to the sqlcmd will be dynamically created using a batch file.
FOR %%i IN ("..\dir1\dir2\*.sql") DO (
echo :r "%%i" >> run.txt)

I need to also include the : error command in the above code with the filename from %%i.Currently if I use
FOR %%i IN ("..\dir1\dir2\*.sql") DO (
echo : error %%i.err >>run.txt
echo :r "%%i" >> run.txt)

the file name with the FULL path and extn .sql.err is printed in run.txt where in :error doesnt accept it in this format.
Please help to proceed.


I think this is what you're looking for:

Code: [Select]FOR %%i IN ("..\dir1\dir2\*.sql") DO (
echo :error %%~ni.err >>run.txt
echo :r "%%i" >> run.txt)

Good luck.



Discussion

No Comment Found