Archive: osql and batch file


osql and batch file
Hi,

I'm having some problem with executing an osql command from a batch file. I've already searched the forum to find information about osql and executing a batch file, but none of the posts could solve my problem.

What I do is execute a batch file with the following rule:
ExecWait '"$EXEDIR\createdb.bat"'

The batch file contains the following lines:
echo off
echo please wait while creating Cr database...
if not exist C:\Cr mkdir C:\Cr
if not exist C:\Cr\Data mkdir C:\Cr\Data
osql -S .\server -Usa -Pmasked -i tlvdc.sql -oC:\Cr\createdb.log


What happens is that the a command window pops up, the directory C:\Cr\Data is created, but the osql command does not execute, the command window closes almost immediately.

Is there anyone that can help me with my problem?

Best regards,

n.s.


Is it important where the osql command is running from (working dir) or is it something that exists in your path? In other words if you run the osql command from anywhere will it work?

As for the batch file I would use something like this instead:

IfFileExists 'C:\Cr\Data\*.*' +2 +1
CreateDirectory 'C:\Cr\Data'
nsExec::Exec '"<path>\osql" -S .\server -Usa -Pmasked -i tlvdc.sql -oC:\Cr\createdb.log'

or you can use ExecWait if you want to see the DOS window popping up ...

Maybe it would be a good idea to add a pause command in your batch file after the osql command to see if it complains for something and that's why it does not execute at all ...
Hope this helps


CF

Thanks for the reply,

After some test I noticed that it had to do with an invalid path (as you suggested).

The problem was that the sql file wasn't in the executing directory.

I used the following to solve the problem:
ExecWait '"$EXEDIR\createdb.bat" $EXEDIR'

And adjusted the batch file like this:

if not exist C:\Cr mkdir C:\Cr
if not exist C:\Cr\Data mkdir C:\Cr\Data
if "%1"=="" goto cont
cd %1
:cont
osql -S .\server -Usa -Pmasked -i tlvdc.sql -oC:\Cr\createdb.log


Best regards,

n.s.