c# – 使用Process.Start在路径中使用参数AND空格

栏目: ASP.NET · 发布时间: 6年前

内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/17321289/use-process-start-with-parameters-and-spaces-in-path

我看过类似的例子,但找不到像我的问题那样的东西.

我需要从C#运行这样的命令:

C:\FOLDER\folder with spaces\OTHER_FOLDER\executable.exe p1=hardCodedv1 p2=v2

我在运行时设置v2,所以我需要在调用Process.Start之前修改C#中的字符串.有谁知道如何处理这个,因为我的参数之间有空格?

您可以使用 ProcessStartInfo

类来分隔参数FileName,WorkingDirectory和参数,而不用担心空格

string fullPath = @"C:\FOLDER\folder with spaces\OTHER_FOLDER\executable.exe"
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Path.GetFileName(fullPath);
psi.WorkingDirectory = Path.GetDirectoryName(fullPath);
psi.Arguments = "p1=hardCodedv1 p2=" + MakeParameter();
Process.Start(psi);

其中MakeParameter是一个返回要用于p2参数的字符串的函数

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/17321289/use-process-start-with-parameters-and-spaces-in-path


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Stylin' with CSS

Stylin' with CSS

Wyke-Smith, Charles / 2012-10 / $ 50.84

In this completely revised edition of his bestselling Stylin' with CSS, veteran designer and programmer Charles Wyke-Smith guides you through a comprehensive overview of designing Web pages with CSS, ......一起来看看 《Stylin' with CSS》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具