【问题标题】:How to run hidden R task?如何运行隐藏的 R 任务?
【发布时间】: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


    【解决方案1】:

    ProcessStartInfo.CreateNoWindow Property 设置为true。这可以防止系统为新进程创建控制台窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 2021-08-20
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      相关资源
      最近更新 更多