我有一个程序,需要从带有参数的cmd中运行,例如名为执行文件的文件
I have a program that needed running from the cmd with arguments, say the execute file called
program.exe
program.exe
我需要使用args从cmd运行它,cmd中的整个命令如下所示:
And i need to run it from the cmd with args, the whole command in the cmd look like this:
c:\ram\program.exe /path = c:\program files\NV如您所见,路径为:"c:\ ram \"
As you can see the path is : "c:\ram\"
执行文件为:"program.exe"
The execute file is : "program.exe"
我需要发送的参数是:/path = c:\ program files \ NV
The args that i need to send is : /path = c:\program files\NV
我该怎么办?
我尝试打开这样的进程:
I try to open process like this :
string strArguments = @"/path = c:\program files\NV"; Process p = new Process(); p.StartInfo.FileName = "program.exe"; p.StartInfo.WorkingDirectory = "c:\\ram\\"; p.StartInfo.Arguments = strArguments; p.Start();而且不好,我认为问题可能出在我没有从CMD访问exe文件,也许我错了……任何人都知道我该怎么做?
And its not good, i figure that the problem could be that i'm not accessing the exe file from the CMD, maybe i'm wrong...any body got idea how can i do it ?
谢谢
推荐答案尝试这些事情
p.StartInfo.FileName ="c:\\ ram \\ program.exe"; 无需设置工作目录
这是问题的根源
string strArguments = @"/path = ""c:\program files\NV""";如果路径中有空格,则必须将整个路径用引号引起来.完整的代码如下
When there is a space in a path, you have to enclose the whole path in quotation marks. The complete code is as follows
string strArguments = @"/path=""c:\program files\NV"""; Process p = new Process(); p.StartInfo.FileName = @"c:\ram\program.exe"; p.StartInfo.Arguments = strArguments; p.Start();它应该完全按照您的意图进行操作.
It should do exactly what are you trying to do.
1.运行"cmd.exe".
1.run "cmd.exe".
2.go到此目录:"c:\ ram \"(当然在cmd中).
2.go to this dir: "c:\ram\" (in the cmd of course).
3.使用以下参数执行文件"program.exe":"/path = c \:program files \ NV"
3.execute the file "program.exe" with this argument: "/path = c\:program files\NV"
它将program.exe放在c:\ ram \文件夹中,并使用带有指定参数的cmd执行该程序.
It takes the program.exe in the c:\ram\ folder and executes it using cmd with the specified arguments.
更多推荐
使用参数从cmd执行程序
发布评论