0

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();

            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();

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Never mind my answer, I see you're getting the batch file to execute correctly since you're getting output in the error text file. So SLaks is correct, your batch file has an error
it solves my problem. im interested in getting the output for now only. thanks.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.