Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何运行隐藏的R任务?_C#_R_Windows_Command Line - Fatal编程技术网

C# 如何运行隐藏的R任务?

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

我正在从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:\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
。这会阻止系统为新进程创建控制台窗口