I execute a command from my C# App.
It runs fine but sometimes I get errors.
My problem is that I cannot see which is the error or any other text in the command window.
It is just blank.
Is there any way I can make the text show up in the execution time same as it is appeared here?
Here is my code:
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
//processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.WorkingDirectory = workingFolder;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("output>>" + e.Data);//MessageBox.Show(e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("error>>" + e.Data);//MessageBox.Show(e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine("ExitCode: {0}", process.ExitCode);
process.Close();


There is nothing wrong with your code, the problem is that you run your program in the wrong path.
Follow these steps to find the path of your app:
Then, in the
cmd.exego to the path with bunch ofcdcommands.Here is the code:
The output:
Also, you can run your app with Ctrl + F5
I know these are so obvious but it's worth to mention them.
Update
You should specify a command, maybe you don't set any command or your command has ~no output~
Update2
I change the code, when the user send
argstomyapp.exe, it directs it to run.Output:
C:\Users\Mahan\Source\Repos\ConsoleApp11\ConsoleApp11\bin\Debug>myapp.exe echo hello