I have a problem with understanding in and out of the ProcessStartInfo class in .NET. I use this class to execute .exe programs like FFmpeg without any problems.
But when I use ProcessStartInfo to run the .cmd program, as a simple foo.cmd file containing only @echo Hello world , it does not output anything.
ProcessStartInfo oInfo = new ProcessStartInfo(@"C:\Program Files (x86)\itms\foo.cmd") { UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow = true }; using (Process p = new Process()) { p.StartInfo = oInfo; p.OutputDataReceived += new DataReceivedEventHandler(transporter_OutputDataReceived); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); } private void transporter_OutputDataReceived(object sender, DataReceivedEventArgs e) { Response.Write(e.Data + " - line<br/>"); }
I have seen many examples where people use cmd.exe to run the .cmd program, and I tried this, but to no avail. The program simply continues to load endlessly.
ProcessStartInfo oInfo = new ProcessStartInfo("cmd", "/c start foo.cmd") { UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow = true, WorkingDirectory = @"C:\Program Files (x86)\itms" };
The foo.cmd program works and displays successfully using the command line tool on Windows and Mac.
Maybe someone wants to demystify this for me.
thanks
EDIT
The code runs correctly when executed locally. The problem occurs when I execute the code on our website. Either the program cannot be executed, or the output is somehow disabled.
Only cmd.exe returns the output '' cmd "," / c dir " is, for example, returning information about the current contents of the folder.
Could this be a resolution problem?
Marle1
source share