C# 如何运行隐藏的R任务?
我正在从c#windows窗体应用程序调用Rscript.exe,cmd窗口将打开几毫秒。python解决方案很简单:只需启动pythonw.exe而不是python.exe 以下是函数:C# 如何运行隐藏的R任务?,c#,r,windows,command-line,C#,R,Windows,Command Line,我正在从c#windows窗体应用程序调用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:\c
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代码>不起作用。将设置为true
。这会阻止系统为新进程创建控制台窗口