简体   繁体   English

从C#启动包含参数的命令行

[英]Start a command line including arguments from C#

I need to start a complete command line like "app.exe /arg1:1 /arg2:true" from my C# app. 我需要从我的C#应用​​程序中启动一个完整的命令行,例如“ app.exe / arg1:1 / arg2:true”。

Process.Start and ProcessStartInfo needs to have the filename and arguments property set. Process.Start和ProcessStartInfo需要设置文件名和参数属性。 Is there a way to mimic a true shell-like execute (like the one when you press WIN+R)? 有没有办法模仿真正的类似于shell的执行(就像按WIN + R时那样)?

Yes, you can launch cmd.exe with the full command-line you want to send as the arguments. 是的,您可以使用要发送的完整命令行作为参数启动cmd.exe

info.FileName = "cmd.exe";
info.Arguments = "app.exe /arg1:1 /arg2:true";

ProcessStartInfo.UseShellExecute使Process.Start的行为与Shell完全相同: http : //msdn.microsoft.com/zh-cn/library/system.diagnostics.processstartinfo.useshellexecute.aspx

I've found the solution I've been looking for: Executing another program from C#, do I need to parse the "command line" from registry myself? 我找到了一直在寻找的解决方案: 从C#执行另一个程序,我是否需要自己解析注册表中的“命令行”?

Thanks again for your help! 再次感谢你的帮助!

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

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