如何在C#中使用更多DOS命令
我在 DOS 中有大约 7 个命令,我想在我的 C# 程序中运行它们。我可以这样做吗:
System.Diagnostics.Process.Start("cmd.exe", "my more commands here");
? 编辑: 我正在制作一个可以运行 g++ 的小应用程序。现在这是正确的吗?:
System.Diagnostics.Process.Start("cmd.exe", "/k cd C:\\Alps\\compiler\\ /k g++ C:\\Alps\\" + project_name + "\\Debug\\Main.cpp");
编译命令:
g++ -c C:\Alps\here_is_projectname\Debug\Main.cpp -o main.o
I have about 7 commands in DOS and I want to run them in my C# program. Can I do:
System.Diagnostics.Process.Start("cmd.exe", "my more commands here");
?
EDIT:
I'm making small app what will run g++. Is this now correct?:
System.Diagnostics.Process.Start("cmd.exe", "/k cd C:\\Alps\\compiler\\ /k g++ C:\\Alps\\" + project_name + "\\Debug\\Main.cpp");
Command for compiling:
g++ -c C:\Alps\here_is_projectname\Debug\Main.cpp -o main.o
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
两者均有效。
/k
将执行命令并留下一个空提示(如果您只想执行以获得反馈,则在您的应用程序中可能不太理想。)/c
将执行命令并在完成后关闭窗口。如果您想从特定目录执行命令,您可以这样做:
Are both valid.
/k
will execute the command and leave you with an empty prompt (probably less desirable in your application if you just want to execute for feedback.)/c
will execute the command and close the window when it has completed.If you're looking to execute a command from a specific directory, you can do:
是的,您可以使用“/C”开关传入命令行:
Yes, you can pass in the command line using the "/C" switch:
您还可以执行以下操作...
如果您需要,processstartinfo 上还有一些选项可以重定向输入和输出
例如..
You can also do like the following....
There are also options on the processstartinfo to redirect input and output if you need to
For example..
您可以启动 cmd.exe 重定向与您的命令一起传输的标准输入和脚。
当然,您应该记住设置进程星号信息以表明您想要重定向输入:
You can launch cmd.exe redirect the stdin and feet that stream with your commands.
Of course you should remeber to set your process star info to say you want redirect input: