C#使用命令提示符执行外部.exe。具有名称空间的可执行根文件夹 [英] C# execute external .exe using command prompt. Executable root folder having space for the name

查看:89
本文介绍了C#使用命令提示符执行外部.exe。具有名称空间的可执行根文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手。我的应用程序需要在C#Winforms中使用命令窗口(cmd.exe)帮助运行另一个.exe文件;





在代码和平之下,其中一个文件夹(My App 4)有一个空格。由于此空间,命令提示符不执行app.exe。



我尝试过:



我试过: -



var process = new ProcessStartInfo();

string Path = @C: \ PROGRA~1 \我的应用4 \比较\ app.exe;

process.UseShellExecute` = true;

proccess.WorkingDirectory = @C :\ Windows \ System32;

process.Filename = @C:\ Windows \ System32 \ cmd.exe;

process.Arguments = / c+路径;

proccess.WindowStyle = ProcessWindowStyle.Hidden;

process.Start(process);

I am new to commands. My application need to run another .exe file with the help of command window (cmd.exe) in C# Winforms;


Below peace of code the one of the folder having(My App 4) a space. Due to this space the command prompt not execute app.exe.

What I have tried:

I tried:-

var process= new ProcessStartInfo();
string Path = @"C:\PROGRA~1\My App 4\Compare\app.exe";
process.UseShellExecute` = true;
proccess.WorkingDirectory = @"C:\Windows\System32";
process.Filename = @"C:\Windows\System32\cmd.exe";
process.Arguments = "/c " + Path;
proccess.WindowStyle = ProcessWindowStyle.Hidden;
process.Start(process);

推荐答案

您尝试执行的路径必须在命令行中用引号括起来。



您似乎尝试执行的命令行是:

The path you're trying to execute has to be enclosed in quotes in your command line.

The command line you appear to be trying to execute is:
cmd /c C:\PROGRA~1\My App 4\Compare\app.exe





你需要执行的是:



What you need to be executing is:

cmd /c "C:\Program Files\May App 4\Compare\app.exe"



Any其中包含空格的路径必须用引号括起来。

因此,设置路径的quick'n'dirty方法将是


Any path that has spaces in it must be enclosed in quotes.
So, the quick'n'dirty method of setting your Path would be

string Path = "\"C:\\Program Files\\My App 4\\Compare\app.exe\"";


您需要将 Path 放在双引号中,因为它用作参数,不是这里的FileName。与手动将其键入命令控制台的情况相同。



您确定自己确实不想直接执行应用程序,而无需绕道而行吗? code> cmd.exe的?像这样:

You would need to put Path in double-quotes because it's used as an argument, not as the FileName here. Same thing as when you would type it into a command console manually.

Are you sure you actually don't want to execute your app directly, without the detour via cmd.exe? Like this:
Process.Start(@"C:\PROGRA~1\My App 4\Compare\app.exe");


这篇关于C#使用命令提示符执行外部.exe。具有名称空间的可执行根文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆