c# - 如何隐藏由于此过程而创建的 CMD 窗口?
问题描述
我正在尝试运行一个可执行文件作为我的程序的一部分,该文件将在事件处理程序中重复调用。目前,被注释掉的第一行和最后一行按应有的方式运行可执行文件,我遇到的问题是尝试使它,以便用户可以选择在弹出时隐藏该可执行文件(使用收音机完成按钮)
Console.WriteLine("Generated Instruction: " + arguments);
//var proc = System.Diagnostics.Process.Start(chartLocation + @"\MODUS CHaRT CMD.exe", arguments ); // Run Command Line instruction
Process myProc = new Process();
if (hideChartStatus) /* make the process invisible */
{
try
{
myProc.StartInfo.CreateNoWindow = true;
myProc.StartInfo.UseShellExecute = false;
Console.WriteLine("Invisible CHART window generated");
}
catch
{
Console.WriteLine("Could not hide CHaRT window");
}
}
else
{
myProc.StartInfo.CreateNoWindow = false;
}
myProc.StartInfo.WorkingDirectory = chartLocation;
myProc.StartInfo.FileName = "\\MODUS CHaRT CMD.exe";
myProc.StartInfo.Arguments = arguments;
myProc.Start();
//myProc = myProc.Start(chartLocation + @"\MODUS CHaRT CMD.exe", arguments);
//proc.WaitForExit();
myProc.WaitForExit();
这是我到目前为止所得到的,但我收到错误“System.ComponentModel.Win32Exception:'系统找不到指定的文件'”
在 myProc.start();
我猜这与我如何使用文件名和工作目录有关?
任何人都知道正确的语法吗?
解决方案
大家别理我,我是个白痴。
更准确地基于这里所做的事情: https ://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netframework-4.7.2
正确的用法是:
//myProc.StartInfo.WorkingDirectory = chartLocation;
myProc.StartInfo.FileName = chartLocation + @"\MODUS CHaRT CMD.exe";
myProc.StartInfo.Arguments = arguments;
myProc.Start();
推荐阅读
- javascript - 获取 NodeList 中元素的值
- python - 使用 powershell 和 python 调用 Rscript
- python - 如何在 tkinter 旁边运行循环?- Python 二维码阅读器图形用户界面
- r - 如何在 R 中以 .png 格式保存绘图
- python - 在 Django 模板中,按钮未按预期工作
- python - Python 错误 - ImportError:尝试相对导入,但没有已知的父包
- google-sheets - 在 Google 电子表格中将列值转置为包含合并单元格的行
- c - 为什么这个程序会在 C 中给出无效的内存访问错误?
- javascript - 我的油门功能没有等待限制时间
- node.js - jest.config.ts:从 Github Actions 运行 jest 时出现“registerer.enabled 不是函数”错误