running batch file, getting error and process output into a text file
hi for the following code, why is it that i am getting this output in the error text file?
"'ha57061' is not recognized as an internal or external command, operable program or batch file."
my user name is cha57061. why am i missing the "c" and " ' "? please correct me if my code is wrong.
System.Diagnostics.Process runantc = new System.Diagnostics.Process();开发者_StackOverflow
runantc.StartInfo.FileName = "C:/Documents and Settings/Cha57061/Desktop/New Folder/WPF/WpfApplication1/WpfApplication1/cmd.exe";
runantc.StartInfo.Arguments = "antc.bat";
runantc.StartInfo.UseShellExecute = false;
runantc.StartInfo.RedirectStandardOutput = true;
runantc.StartInfo.RedirectStandardError = true;
runantc.Start();
string procOutput = runantc.StandardOutput.ReadToEnd();
string procError = runantc.StandardError.ReadToEnd();
TextWriter outputlog = new StreamWriter("C:/Documents and Settings/Cha57061/Desktop/New Folder/WPF/WpfApplication1/WpfApplication1/processoutput.txt");
outputlog.Write(procOutput);
outputlog.Close();
TextWriter outputerror = new StreamWriter("C:/Documents and Settings/Cha57061/Desktop/New Folder/WPF/WpfApplication1/WpfApplication1/error.txt");
outputerror.Write(procError);
outputerror.Close();
Not sure if it solves your problem, but this is the first time i'm seeing file paths in C#.NET using forward slashes (/), not sure if they get converted to (\) automatically. You might try rewriting your paths as indicated below
"C:\\Directory\\File" //the double slash is necessary since (\) indicates an escape character is to come)
@"C:\Directory\" // the @ modifier changes the default behavior and escape characters are not considered the same way
\c is a escape character, as described here: http://msdn.microsoft.com/en-us/library/4edbef7e%28v=vs.71%29.aspx
That's the wrong way to run a batch file.
You should set FileName
directly to the path to your .bat
file.
To answer your question, your batch file has a problem.
精彩评论