【发布时间】:2016-01-24 23:44:22
【问题描述】:
我从 c# windows forms 应用程序调用 Rscript.exe,cmd 窗口打开了几毫秒。 python的解决方案很简单:只需启动pythonw.exe而不是python.exe
函数如下:
private void runr()
{
orig = richTextBox1.Text;
System.IO.File.WriteAllText(@"C:\cp.R", richTextBox1.Text);
string cmd = @"C:\cp.R";
string args = @"";
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Program Files\R\R-3.2.3\bin\Rscript.exe";
start.Arguments = string.Format("{0} {1}", cmd, args);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
StreamReader reader2 = process.StandardError;
string err = reader2.ReadToEnd();
richTextBox1.Text = result;
if (!string.IsNullOrEmpty(err))
richTextBox1.Text += "\nError:\n" + err;
}
}
}
设置start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 不起作用。
【问题讨论】:
标签: c# r windows command-line