C# 中的命令行参数
再次大家好 Stackoverflow 社区,
今天我尝试在 C# 中使用命令行参数执行一个应用程序,这并不像我尝试
Process.Start(foldervar + "cocacola.exe", "pepsi.txt");
Cocacola.exe 写入并登录其当前文件夹那样困难。在我的命令行中,我像这样手动编写它,
C:\myfolder>cocacola.exe pepsi.txt
效果很好,但如果我在 C# 中尝试,则完全失败。
我读到 C# 将命令解析为 C:\myfolder>cocacola pepsi.txt,没有“.EXE”结尾。而且我手动测试了一下没有结局,这行不通。
现在,我的问题是让 C# 执行它的正确方法是什么 C:\myfolder>cocacola.exe pepsi.txt 带有“.EXE”
Hello again Stackoverflow community,
Today I am trying to execute an application with commandline parameters in C#, that not realy difficult like I tried
Process.Start(foldervar + "cocacola.exe", "pepsi.txt");
Cocacola.exe writes and Log in its current folder. In my commandline I write it manually like this
C:\myfolder>cocacola.exe pepsi.txt
Works wonderful but if I try it in C# a total fail.
I read that C# parses the command as C:\myfolder>cocacola pepsi.txt, without the ".EXE" ending. And I tested it manually without the ending, and this does not work.
Now, my question is what is the correct way to get C# executing it C:\myfolder>cocacola.exe pepsi.txt with the ".EXE"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 ProcessStartInfo
http://www.dotnetperls.com/process-start
示例:
这里是文档StartInfo 属性:
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
use ProcessStartInfo
http://www.dotnetperls.com/process-start
example:
here is docs on the StartInfo properties:
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
尝试设置
StartInfo
属性。Try setting the
StartInfo
properties.ProcessStartInfo
具有WorkingDirectory
属性,您应将其设置为 C:\myfolder请参阅:http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx
ProcessStartInfo
has theWorkingDirectory
property you should set to C:\myfoldersee: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx
您需要先设置工作目录
设置工作目录相当于在运行程序之前
cd
进入正确的目录。这就是相对路径的相对路径。You need to set the working directory first
Setting the WorkingDirectory is equivilent to
cd
ing into the proper directory before running programs. It's what relative paths are relative to.