/// 执行CMD命令 public static void Run(object data) { // 弹出新窗口 Command_window_display f = new Command_window_display(); string cmd = data.ToString(); Process p = newProcess("cmd.exe"); //向cmd窗口发送输入信息 string strInput1 = "activate gprmax"; string strInput2 = cmd; //向cmd窗口发送输入信息 p.StandardInput.WriteLine(strInput1); p.StandardInput.WriteLine(strInput2); p.StandardInput.AutoFlush = true; //获取输出信息 string strOuput = p.StandardOutput.ReadToEnd(); //等待程序执行完退出进程 p.WaitForExit(); p.Close(); //Console.WriteLine(strOuput); //Console.ReadKey(); //显示 f.richTextBox1.Text = strOuput; f.ShowDialog(); }
private void Combined2_Click(object sender, EventArgs e) { // 弹出新窗口 Command_window_display f = new Command_window_display(); status_bar.Text = "正在初始化!"; Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; //设置要启动的应用程序 p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 p.StartInfo.RedirectStandardInput = true; // 接受来自调用程序的输入信息 p.StartInfo.RedirectStandardOutput = true; //输出信息 p.StartInfo.RedirectStandardError = true; // 输出错误 p.StartInfo.CreateNoWindow = true; //不显示程序窗口 //启动程序 p.Start(); //如果目标路径不存在,则创建目标路径 string subPath = System.IO.Path.Combine("{0}", "{1}", path, name); // B扫描绘图合成(删除) string strInput1 = "activate gprmax"; string strInput2 = "python -m tools.outputfiles_merge " + subPath + " --remove-files"; Application.DoEvents(); status_bar.Text = "正在合成!"; //向cmd窗口发送输入信息 p.StandardInput.WriteLine(strInput1); p.StandardInput.WriteLine(strInput2 + "&exit"); //p.StandardInput.WriteLine("exit"); p.StandardInput.AutoFlush = true; string strOuput = p.StandardOutput.ReadToEnd(); //获取输出信息 p.WaitForExit(); //等待程序执行完退出进程 p.Close(); Application.DoEvents(); status_bar.Text = "合成成功!"; f.richTextBox1.Text = strOuput; f.ShowDialog(); }
private void A_scan2_Click(object sender, EventArgs e) { // 弹出新窗口 Command_window_display f = new Command_window_display(); status_bar.Text = "正在初始化!"; Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; //设置要启动的应用程序 p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 p.StartInfo.RedirectStandardInput = true; // 接受来自调用程序的输入信息 p.StartInfo.RedirectStandardOutput = true; //输出信息 p.StartInfo.RedirectStandardError = true; // 输出错误 p.StartInfo.CreateNoWindow = true; //不显示程序窗口 //启动程序 p.Start(); // A扫描绘图 string strInput1 = "activate gprmax"; path += ".out"; string strInput2 = "python -m tools.plot_Ascan " + path; Application.DoEvents(); status_bar.Text = "正在生成!"; //向cmd窗口发送输入信息 p.StandardInput.WriteLine(strInput1); p.StandardInput.WriteLine(strInput2 + "&exit"); //p.StandardInput.WriteLine("exit"); p.StandardInput.AutoFlush = true; string strOuput = p.StandardOutput.ReadToEnd(); //获取输出信息 p.WaitForExit(); //等待程序执行完退出进程 p.Close(); Application.DoEvents(); status_bar.Text = "图像生成成功!"; f.richTextBox1.Text = strOuput; f.ShowDialog(); }
private void Button3_Click(object sender, EventArgs e) { string model_name = this.text_name.Text; string catalog = @comboBox1.SelectedItem.ToString(); string path = System.IO.Path.Combine("{0}", "{1}", catalog, model_name + ".in"); //打开一个文本,读取所有行,然后关闭该文档 string str1 = File.ReadAllText(path); if (!str1.Contains("#geometry_view")) { string geometry_view = String.Format("#geometry_view: 0 0 0 {0} {1} {2} {3} {4} {5} test_half_space n", domain_x.Text, domain_y.Text, domain_z.Text, dx.Text, dy.Text, dz.Text); File.AppendAllText(path, geometry_view); } // 弹出新窗口 Command_window_display f = new Command_window_display(); /* * Console.WriteLine("请输入要执行的命令:"); * string strInput = Console.ReadLine(); */ Application.DoEvents(); StatusLabel.Text = ""; Thread.Sleep(5000);//睡眠500毫秒,也就是0.5秒 StatusLabel.Text = "正在初始化!"; Process p = new Process(); //设置要启动的应用程序 p.StartInfo.FileName = "cmd.exe"; //是否使用操作系统shell启动 p.StartInfo.UseShellExecute = false; // 接受来自调用程序的输入信息 p.StartInfo.RedirectStandardInput = true; //输出信息 p.StartInfo.RedirectStandardOutput = true; // 输出错误 p.StartInfo.RedirectStandardError = true; //不显示程序窗口 p.StartInfo.CreateNoWindow = true; Application.DoEvents(); Thread.Sleep(500);//睡眠500毫秒,也就是0.5秒 StatusLabel.Text = ""; //启动程序 p.Start(); string strInput1 = "activate gprmax"; string strInput2 = "python -m gprMax " + path + " --geometry-only"; Application.DoEvents(); StatusLabel.Text = "初始化成功,正在导入!"; Application.DoEvents(); Thread.Sleep(500);//睡眠500毫秒,也就是0.5秒 StatusLabel.Text = ""; //向cmd窗口发送输入信息 p.StandardInput.WriteLine(strInput1); p.StandardInput.WriteLine(strInput2 + "&exit"); //p.StandardInput.WriteLine("exit"); p.StandardInput.AutoFlush = true; //获取输出信息 string strOuput = p.StandardOutput.ReadToEnd(); //等待程序执行完退出进程 p.WaitForExit(); p.Close(); Application.DoEvents(); StatusLabel.Text = "导入成功!!"; f.richTextBox1.Text = strOuput; f.ShowDialog(); /* * Console.WriteLine(strOuput); * Console.ReadKey(); */ }