I'm trying to use the System.Diagnostics.Process
class to run a Perl script from within an ASP.NET application. The Perl command runs fine when I type it into the command line, but when ASP.NET tries to run the same command it doesn't work.
I suspect it may have to do with input and output stream. The Perl script takes a long time to run to completion on the command line. But in .NET the command returns almost immediately, and when I try to redirect Perl script's standard output to see what messages are yielded it shows just the first line and returns. Using blocking stream reading techniques doesn't fix this; .NET really thinks that the Perl script is outputting just one line, then finishes.
Any suggestions? As much as I would like to, the script can't be rewritten in .NET. Here's the code I'm using to launch the process. I've tried changing ReadToEnd()
to a series of ReadLine()
calls, but after the first call returns the first line of output the next call returns null.
Process proc = new Process();
proc.StartInfo.FileName = scriptPath;
proc.StartInfo.Arguments = arguments;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
string output = proc.StandardOutput.ReadToEnd(); // Returns only the first line
proc.WaitForExit();