A
Andrew Falanga
Hi,
I'm struggling to understand how to properly use the
System.Diagnostics.Process class correctly. Here's what I'm doing:
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"c:\windows
\system32\cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StandardInput.AutoFlush = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.StandardInput.WriteLine("C:");
myProcess.StandardInput.WriteLine("cd C:\\Program Files\
\Microsoft Visual Studio 9.0\\VC");
myProcess.StandardInput.WriteLine("vcvarsall.bat");
myProcess.StandardInput.WriteLine("D:");
I can't execute any of the commands without getting the exception,
"StandardIn has not been redirected." Yet, I have
myProcess.StartInfo.RedirectStandardInput set to true.
I've done some searches on the net and I've not seen much different
than what I'm doing. Except, and most notably, in all cases I see the
instantiation of a System.Diagnostics.ProcessStartInfo object and then
a call to Process as in:
System.Diagnostics.ProcessStartInfo procStartInfo = new
System.Diagnostics.ProcessStartInfo();
// set the attributes
System.Diagnostics.Process myProc = new System.Diagnostics.Process
(procStartInfo);
I don't quite understand how that would make it different, but I've
not seen any example on the net that does it as I'm currently doing
it.
Also, where are StandardInput and StandardOutput being redirected?
Andy
I'm struggling to understand how to properly use the
System.Diagnostics.Process class correctly. Here's what I'm doing:
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"c:\windows
\system32\cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StandardInput.AutoFlush = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.StandardInput.WriteLine("C:");
myProcess.StandardInput.WriteLine("cd C:\\Program Files\
\Microsoft Visual Studio 9.0\\VC");
myProcess.StandardInput.WriteLine("vcvarsall.bat");
myProcess.StandardInput.WriteLine("D:");
I can't execute any of the commands without getting the exception,
"StandardIn has not been redirected." Yet, I have
myProcess.StartInfo.RedirectStandardInput set to true.
I've done some searches on the net and I've not seen much different
than what I'm doing. Except, and most notably, in all cases I see the
instantiation of a System.Diagnostics.ProcessStartInfo object and then
a call to Process as in:
System.Diagnostics.ProcessStartInfo procStartInfo = new
System.Diagnostics.ProcessStartInfo();
// set the attributes
System.Diagnostics.Process myProc = new System.Diagnostics.Process
(procStartInfo);
I don't quite understand how that would make it different, but I've
not seen any example on the net that does it as I'm currently doing
it.
Also, where are StandardInput and StandardOutput being redirected?
Andy