简体   繁体   English

如何在 C# 上执行 2 个不同的命令 cmd

[英]How to execute 2 different commands cmd on C#

I was working on a project which needs to run two cmd commands on C#, I looked up on how to do it but nothing worked for me, and everyone was giving the solution to execute only one cmd command.我正在研究一个需要在 C# 上运行两个 cmd 命令的项目,我查看了如何做到这一点,但对我没有任何帮助,每个人都给出了只执行一个 ZDFFF0A7FA1A55C8C1A4966C19F6DA425 命令的解决方案。

I would like to execute one command when the user clicks a button, then another one right after, without quitting the cmd, and if possible to hide the cmd window.我想在用户单击一个按钮时执行一个命令,然后立即执行另一个命令,而不退出 cmd,如果可能的话,隐藏 cmd Z05B8C74CBD96FBF2DE4C1A352702FFF4Z。

My goal would be to execute the 2 following commands in the cmd, to run a Run.bat file:我的目标是在 cmd 中执行以下 2 个命令,以运行 Run.bat 文件:

cd C:\users\user\documents\file
Run.bat

Thanks.谢谢。

You can directly call "C:\users\user\documents\file\Run.bat" and set the working directory as well as the shell execute flag:您可以直接调用“C:\users\user\documents\file\Run.bat”并设置工作目录以及 shell 执行标志:

string path = @"C:\users\user\documents\file\";
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = path + "Run.bat";
process.StartInfo.WorkingDirectory = path;
process.StartInfo.UseShellExecute = true;
process.Start();
//process.WaitForExit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM