cannot start a Process and access standardInput

  • Thread starter Thread starter Juan Gabriel Del Cid
  • Start date Start date
J

Juan Gabriel Del Cid

Process.Start(StartInfo); //line 12
R_Input = Rprocess.StandardInput; //ine 13

I can see the process start correctly after line 12 (it appears
in the Windows Task Manager, and a console starts up).
But line 13 always raises the exception:
"StandardIn has not been redirected."

Um... in line 12 you get the actual process that was created. Store that
reference in Rprocess. In other words, change line 12 to:

Rprocess = Process.Start(StartInfo);

That should work,
-JG
 
I looked at
http://www.codeproject.com/csharp/LaunchProcess.asp?target=process and
tried to follow the code there. My code is:

public class Test
{
public ProcessStartInfo StartInfo;
public StreamWriter R_Input;
public StreamReader R_Output;
public Process Rprocess = new Process();

public Test()
{
}

public void StartR()
{
StartInfo = new ProcessStartInfo(
@"C:/Program Files/R/rw1062/bin/Rterm.exe",
@"--no-restore --no-save");

StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = false;


Process.Start(StartInfo); //line 12

R_Input = Rprocess.StandardInput; //ine 13
}
}

I can see the process start correctly after line 12 (it appears in the
Windows Task Manager, and a console starts up). But line 13 always raises
the exception:
"StandardIn has not been redirected."

I don't know much about the program Rterm.exe itself
(http://www.r-project.org/), but the documentation would imply no problem in
redirecting stdIn and stdOut in a .bat file:

"Otherwise you can set up a batch file using Rterm.exe. A sample batch file
might contain (as one line)

path_to_R\bin\Rterm.exe --no-restore --no-save < %1 > %1.out 2>&1"
Can someone suggest a cause and a fix for this problem?
 
Back
Top