使用参数从cmd执行程序

编程入门 行业动态 更新时间:2024-10-26 11:13:48
本文介绍了使用参数从cmd执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个程序,需要从带有参数的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执行程序

本文发布于:2023-11-23 09:54:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621017.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   程序   cmd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!