unable to run a batch file
i have a batch file to run ssis packages which i can run manually. but i have created a visual studio test project and then call this batch file from a test on the test agent system. But when i run the test i get an error running the batch file. the content of the batch file (run_odw.bat) is : cd C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn dtexec.exe /DTS "\MSDB\Omada\ODW\Omada ODW Configuration" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E dtexec.exe /DTS "\MSDB\Omada\ODW\Omada ODW Import" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E program calling this batch file is public static void ExecuteCommand(string command) { int ExitCode; ProcessStartInfo ProcessInfo; Process process; ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; // *** Redirect the output *** ProcessInfo.RedirectStandardError = true; ProcessInfo.RedirectStandardOutput = true; process = Process.Start(ProcessInfo); process.WaitForExit(); // *** Read the streams *** string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); ExitCode = process.ExitCode; //Base.RunScript(""); //WriteTextFile.writeString("","C:\\output.txt"); // Compose a string that consists of three lines. //string lines = "First line.\r\nSecond line.\r\nThird line."; // Write the string to a file. System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt"); //file.WriteLine(lines); file.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output)); file.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error)); file.WriteLine("ExitCode: " + ExitCode.ToString(), "ExecuteCommand"); file.Close(); process.Close(); } error received in the text file : output>> C:\Users\Administrator\AppData\Local\VSEQT\QTAgent\d4e1b6b6-ba04-45ae-b1df-e47c89e3659a\VM-TC-MNA\Deployment>cd C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn>dtexec.exe /DTS "\MSDB\Omada\ODW\Omada ODW Configuration" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn>dtexec.exe /DTS "\MSDB\Omada\ODW\Omada ODW Import" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E error>>'dtexec.exe' is not recognized as an internal or external command, operable program or batch file. 'dtexec.exe' is not recognized as an internal or external command, operable program or batch file. ExitCode: 1 when i run the same batch file manually it runs fine. mohit narang
May 18th, 2012 7:02am

Hi, since your path has spaces try like this: cd "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn" Or you can specify the full path in dtexec.exe: "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\dtexec.exe" /DTS "\MSDB\Omada\ODW\Omada ODW Configuration" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E David.
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2012 7:07am

Hi, since your path has spaces try like this: cd "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn" Or you can specify the full path in dtexec.exe: "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\dtexec.exe" /DTS "\MSDB\Omada\ODW\Omada ODW Configuration" /SERVER "localhost" /CHECKPOINTING OFF /REPORTING E David. but as you can see that in the output file the path is successfully changed so its not an issue at all. If it had been an issue i would not have been able to run the batch file manually. And also if it was an issue the path should not have changed successfully as we can see in the output part of text file.mohit narang
May 18th, 2012 7:13am

How does the ExecuteCommand process the batch file? It's called 1 time or 3 times (for each line in batch file)? And have you tried putting the whole path for the dtexec.exe commands? David.
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2012 7:25am

yes i have tried putting the whole path as well. the batch file is called only once as can be seen through the output text file, if it had been called three times we should have received the log 3 times.mohit narang
May 18th, 2012 7:38am

Sounds like permissions could be an issue - what credential is the application running under? Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2012 1:58pm

Sounds like permissions could be an issue - what credential is the application running under? Talk to me now on
May 18th, 2012 2:00pm

i will draw the architecture for you to understand better.  as you can see in the drawing everything is working fine and i think it is with the environment of the powershell that i am unable to resolve the path or environment variables when i am running the same file manually on the virtual host. work-around which is working (but really annoying) is that i wrote a service running under the administrator account on the virtual host and it takes the powershell scripts as the parameters and whenever the test methods starts this service it supplies the batch file path as arguments like "sc start myservice "c:\\odw_run.bat" " .. and guess what it runs fine without any issues but the problem is that this method is asynchronous and also the like fire and forget so i don't know if the call is successful or not and how much time to wait for the results. Let me know if you need more details.mohit narang
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2012 2:31pm

So after failing with powershell i tried calling a process but still getting this issue i mentioned in the first post. Thanks for taking your time seeing the problem. I have almost tried all the approaches but i am unable to see dtexec in the powershell script call or system.process call to a batch file. if it is something related to credentials i can supply it but i couldn't find anything on web (maybe someone can rephrase my question better than me :) )...mohit narang
May 18th, 2012 2:35pm

Thanks for your reply but it is not an issue with the path as you are suggesting as i have already done that and you can see in the output file as well that i first change to that path and in the second line the path is changed to new one. I actually solved this problem with a service model. Why a service is needed ? : because of the rights, i make a very trivial service which accepts the path of the script to be run and then runs that script using the system.process and since the rights are an issue i run it under one of the administrator account pools so whenever this service is called it runs our script and for your info. the same script is running fine under this model. mohit narang
Free Windows Admin Tool Kit Click here and download it now
May 21st, 2012 3:45am

Thanks for your reply but it is not an issue with the path as you are suggesting as i have already done that and you can see in the output file as well that i first change to that path and in the second line the path is changed to new one. I actually solved this problem with a service model. Why a service is needed ? : because of the rights, i make a very trivial service which accepts the path of the script to be run and then runs that script using the system.process and since the rights are an issue i run it under one of the administrator account pools so whenever this service is called it runs our script and for your info. the same script is running fine under this model. mohit narang
May 21st, 2012 3:47am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics