So I've read a lot of post about how to run a batch file from within the C# program. And I followed the instructions with a few alterations to fit my needs. First I am using cmd.exe to actually run the script because I want to take advantage of the /K option, so that the log will be onscreen. And second the batch file must be able to call other batch files in a cascading effect. Which it isn't able to do.
So when I run the follow function, with
pathToScripts ="C:\\WORKINGDI RECTORY"
batchfiles ="mybatchfile.b at"
I get this error:
'mybatchfile_ca lled1.bat' is not recognized as an internal or external command,
operable program or batch file.
'mybatchfile_ca lled2.bat' is not recognized as an internal or external command,
operable program or batch file.
C:\AppPath\MyAp p\bin\Release>
So when I run the follow function, with
pathToScripts ="C:\\WORKINGDI RECTORY"
batchfiles ="mybatchfile.b at"
Code:
//---------------------------------------------------------------------------------------------------------- // ExecuteScript - runs a batch file using cmd.exe with a /k (keep on screen) // parameter. //---------------------------------------------------------------------------------------------------------- public static void ExecuteScript(string pathToScripts, string batchfile ) { try { string sCmd = "C:\\WINDOWS\\system32\\cmd.exe"; string sTPath = Path.Combine(pathToScripts, batchfile); ProcessStartInfo psi = new ProcessStartInfo(sCmd); psi.WorkingDirectory = InQuotes(pathToScripts); psi.Arguments = " /T:2F /D /K " + InQuotes(sTPath); psi.UseShellExecute = true; Process cmd = new Process(); cmd.StartInfo = psi; if (!cmd.Start()) { MessageBox.Show("Error", MessageBoxButtons.OK); } } catch (Exception e) { MessageBox.Show(e.ToString(), " ", MessageBoxButtons.OK); } }
'mybatchfile_ca lled1.bat' is not recognized as an internal or external command,
operable program or batch file.
'mybatchfile_ca lled2.bat' is not recognized as an internal or external command,
operable program or batch file.
C:\AppPath\MyAp p\bin\Release>
Comment