private void RunR() { var path = System.IO.Path.GetDirectoryName(Application.ExecutablePath); var cmd = ClassificationRadioButton.Checked ? "class.R" : "function.R"; var args = path.Replace("\\", "/") + "/"; var process = new Process { StartInfo = new ProcessStartInfo { FileName = "Rscript.exe", Arguments = cmd + " " + args, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }, EnableRaisingEvents = true }; process.ErrorDataReceived += ProcessR_OutputDataReceived; process.OutputDataReceived += ProcessR_OutputDataReceived; Debug.WriteLine(cmd + " " + args); process.Start(); process.BeginOutputReadLine(); RLabel.Invoke((MethodInvoker)(() => { RLabel.Visible = true; } )); }
private void ProcessR_OutputDataReceived(object sender, DataReceivedEventArgs e) { Debug.WriteLine(e.Data); if (e.Data == null) { return; } string data = e.Data.ToString().Replace("\"", ""); if (data.Contains("[1] ")) { ChartBox.Invoke((MethodInvoker)(() => { ChartBox.Image = Image.FromFile(data.Substring(4, data.Length - 4) + ".png"); } )); RLabel.Invoke((MethodInvoker)(() => { RLabel.Visible = false; } )); } }