I have the following code:
String Antcbatchpath = @"C:\GUI\antc.bat";
System.Diagnostics.Process runantc = new System.Diagnostics.Process();
runantc.StartInfo.FileName = Antcbatchpath;
runantc.StartInfo.UseShellExecute = false;
runantc.StartInfo.RedirectStandardOutput = true;
runantc.StartInfo.RedirectStandardError = true;
runantc.Start();
Will this load the batch file from C:\GUI\antc.bat
?
O开发者_StackOverflow社区r runantc.StartInfo.FileName
is only for a root directory? Root directory is where the application is located
EDIT 1:
hi instead of @"C:\GUI\antc.bat" i have a path:
String Antcbatchpath =@"C:\GUI Lab Tools\Build Machine\antc.bat";
which essentially contains white spaces. will it affect the runantc.StartInfo.Filename = Antcbatchpath;
?
UseShellExecute = true
should do it.
Alternatively, if you need redirection, use:
runantc.StartInfo.FileName = "CMD.EXE";
runantc.StartInfo.Arguments = "/C " + Antcbatchpath;
You can try to set WorkingDirectory
to prevent any ambiguity, but in my experience, it is not necessary.
The problem you're having is because antc.bat
is not an executable. It requires UseShellExecute
to be true, but that would prevent you from redirecting the output. I guess you will have to choose either one.
精彩评论