Problem running a .bat file from a C# forms application
-
I have this code developed to run a bat file. the code is set to a buttonclick event......bat file is crating correctly ..when i double click on it it works fine..but the bat is not executing from the program..cant figure out what the reason..your help is appriciated..
string text = "compdld -d -i\"C:\\softpay\\ver22\\output\\cpac\\ads\\files\\softpayx.dld\" -w\"C:\\HSBMFC\" -momni-5150 -aHSBMFC -tTID01 -gl -fl";
File.WriteAllText(@"C:\COMPDLD\a.bat", text);
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\COMPDLD\a.bat";
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.EnableRaisingEvents = true;
p.Start();while (!p.HasExited) { System.Threading.Thread.Sleep(1000); } if (p.ExitCode != 0) { //some error occurred }
-
I have this code developed to run a bat file. the code is set to a buttonclick event......bat file is crating correctly ..when i double click on it it works fine..but the bat is not executing from the program..cant figure out what the reason..your help is appriciated..
string text = "compdld -d -i\"C:\\softpay\\ver22\\output\\cpac\\ads\\files\\softpayx.dld\" -w\"C:\\HSBMFC\" -momni-5150 -aHSBMFC -tTID01 -gl -fl";
File.WriteAllText(@"C:\COMPDLD\a.bat", text);
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\COMPDLD\a.bat";
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.EnableRaisingEvents = true;
p.Start();while (!p.HasExited) { System.Threading.Thread.Sleep(1000); } if (p.ExitCode != 0) { //some error occurred }
Good morning. May be you should also specify the working directory. or try to launch cmd.exe with your batch file as argument (same command as the one created when you make a shorcut on a batch file: C:\WINDOWS\system32\cmd.exe /k mybatch.bat. Regards.
-
Good morning. May be you should also specify the working directory. or try to launch cmd.exe with your batch file as argument (same command as the one created when you make a shorcut on a batch file: C:\WINDOWS\system32\cmd.exe /k mybatch.bat. Regards.
Get the standard output stream from the process
Natza Mitzi
-
Good morning. May be you should also specify the working directory. or try to launch cmd.exe with your batch file as argument (same command as the one created when you make a shorcut on a batch file: C:\WINDOWS\system32\cmd.exe /k mybatch.bat. Regards.
You actually should do both (specify the correct working folder and using cmd.exe).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001