【发布时间】:2016-07-04 22:35:37
【问题描述】:
您好 StackOverflow 用户。我正在尝试编写一些代码来打开一个新的控制台/终端窗口,启动 GnuPlot,执行gnuplot 命令,然后使用plot sin(x) 绘制正弦函数。
请注意,如果您在 gnuplot 命令中运行它,它只会打印出来。 GnuPlot 程序有点像 Python shell,如果您还没有了解的话。
问题
我可以让它执行gnuplot,很好,它在当前窗口上运行命令(不是这个问题的问题,但请随时解决!) 但它不将plot sin(x) 识别为命令。我的猜测是它会执行 gnuplot 并以某种方式退出 GnuPlot shell 并返回正常的控制台模式。
注意:我使用的是 KUbuntu 16.04 LTS。
代码
public void Plot() {
// GetCommand() always returns "gnuplot" for now.
ProcessStartInfo pInfo = new ProcessStartInfo("/bin/bash", String.Format("-c {0};plot sin(x)", GetCommand())) {
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false
};
Process process = new Process () { StartInfo = pInfo };
process.Start ();
}
控制台返回错误:sin(x): plot: command not found。
我尝试过的
要将; plot sin(x) 替换为&& plot sin(x),将返回相同的错误。
要使用process.StandardInput.WriteLine ("plot sin(x)"); 行写入StandardInput,但是它会抛出一个System.InvalidOperationException 通知Standard input has not been redirected,即使我在ProcessStartInfo 上重定向它!
【问题讨论】: