Forum Discussion
tristaanogre
15 years agoEsteemed Contributor
First of all, minor correction: OSQL will be phased out by Microsoft and they recommend using the utility you've already specified, SQLCMD.
My suggestion is that, rather than running the command prompt and executing a "Keys" command on the resulting window, to utilize the WScript.Shell object to execute the command line and have it wait for the command to return before continuing. Information on Wscript.Shell and related objects can be found at http://msdn.microsoft.com/en-us/library/ahcz2kh6(v=VS.85).aspx
Here is my suggestion for the code you've posted (JScript so you will need to adapt).
This will execute exactly the commandline you want to within a windows shell. The "true" parameter indicates to wait until the command completes before returning. I believe this will do what you need it to do.
My suggestion is that, rather than running the command prompt and executing a "Keys" command on the resulting window, to utilize the WScript.Shell object to execute the command line and have it wait for the command to return before continuing. Information on Wscript.Shell and related objects can be found at http://msdn.microsoft.com/en-us/library/ahcz2kh6(v=VS.85).aspx
Here is my suggestion for the code you've posted (JScript so you will need to adapt).
function Test()
{
var ShellObj = Sys.OleObject("WScript.Shell");
ShellObj.Run(ComandoCriarTabela + "2.Nucleo\SQLServer\1.sql", 1, true);
}
This will execute exactly the commandline you want to within a windows shell. The "true" parameter indicates to wait until the command completes before returning. I believe this will do what you need it to do.