And*_*ech 37
这是一个简单的例子:
Process.Start("cmd","/C copy c:\\file.txt lpt1");
Run Code Online (Sandbox Code Playgroud)
Ash*_*vis 22
正如其他答案所述,您可以使用:
Process.Start("notepad somefile.txt");
Run Code Online (Sandbox Code Playgroud)
但是,还有另一种方式.
您可以实例化Process对象并调用Start实例方法:
Process process = new Process();
process.StartInfo.FileName = "notepad.exe";
process.StartInfo.WorkingDirectory = "c:\temp";
process.StartInfo.Arguments = "somefile.txt";
process.Start();
Run Code Online (Sandbox Code Playgroud)
这样做可以让您在开始流程之前配置更多选项.Process对象还允许您在执行过程中检索有关进程的信息,并在进程完成时向您发出通知(通过Exited事件).
另外:如果要挂钩'已退出'事件,请不要忘记将'process.EnableRaisingEvents'设置为'true'.
Mit*_*eat 10
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("example.txt");
}
}
Run Code Online (Sandbox Code Playgroud)
Zvi*_*adi 10
如果要使用cmd启动应用程序,请使用以下代码:
string YourApplicationPath = "C:\\Program Files\\App\\MyApp.exe"
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.FileName = "cmd.exe";
processInfo.WorkingDirectory = Path.GetDirectoryName(YourApplicationPath);
processInfo.Arguments = "/c START " + Path.GetFileName(YourApplicationPath);
Process.Start(processInfo);
Run Code Online (Sandbox Code Playgroud)
如何使用所需命令创建批处理文件,并使用Process.Start调用它
dir.bat内容:
dir
Run Code Online (Sandbox Code Playgroud)
然后打电话:
Process.Start("dir.bat");
Run Code Online (Sandbox Code Playgroud)
将调用bat文件并执行dir
您是想问如何调出命令窗口吗?如果是这样,您可以使用Process 对象...
Process.Start("cmd");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134648 次 |
| 最近记录: |