1

我正在努力使用 c# 在 pig grunt shell 上执行命令。我可以使用以下代码通过 c# 程序启动 grunt shell:

proc = new Process {StartInfo = new ProcessStartInfo
                    {
                        FileName = PIG_BIN + "\\pig.cmd",                
                        UseShellExecute = false,
                        RedirectStandardError = true ,
                        RedirectStandardOutput = true,
                        RedirectStandardInput = true,
                        CreateNoWindow = true
                    }
                };

我通过以下方法和事件读取了输出和错误:

     proc.OutputDataReceived += proc_OutputDataReceived;
  proc.BeginOutputReadLine();
  proc.ErrorDataReceived += proc_ErrorDataReceived;
  proc.BeginErrorReadLine();

但是,我无法从 grunt shell 读取输出行。但是,只有“grunt>”之前的行是单独读取的。

我通过以下命令将参数传递给 grunt shell,

proc.StandardInput.WriteLine("dump a;");

我也无法将参数传递给 grunt shell。当我们启动 grunt shell 时会启动一个 java 进程。如果我在命令提示符下结束 java.exe,则会触发“OutputDataReceived”事件并获得“grunt>”。

我希望 grunt 作为 java 进程运行,因此我们无法向它传递和接收参数。有什么办法可以实现吗??

4

0 回答 0