问题描述
我必须在c#
执行命令行
执行命令行(@Files +\\CON.exe+ MHTFile ++模板) ;
模板字符串之间有空格所以它不工作
如何在c#中执行此操作?
提前谢谢。
I have to execute a command line in c#
ExecuteCommandLine(@Files + "\\CON.exe " + MHTFile + " " + template);
the template string have space in between so its not working
how to execute this in c# ?
Thanks in advance.
推荐答案
var str1 = "a string without quotes";
var str2 = "\"a string surrounded by quotes\"";
Console.WriteLine("|{0}|", str1);
Console.WriteLine("|{0}|", str2);
给出结果
which gives the results
|a string without quotes|
|"a string surrounded by quotes"|
如果模板
在任何时候都不包含空格,则引号无害。
所以在你的情况下,你可以尝试
If at any time template
does not contain spaces, the quotes are harmless.
So in your case you could try
var template = "\"a string with quotes\"";
或
ExecuteCommandLine(@Files + "\\CON.exe " + MHTFile + " " + "\"" + template + "\"");
ExecuteCommandLine(@Files + "\\CON.exe \"" + MHTFile + " " + template + "\"");
这是否有效取决于你的ExecuteCommandLine方法对你传递的数据做了什么:我自己将它传递给两个字符串 - 一个是exe,另一个是参数,并使用Process.Start重载代替两个参数: []
Whether that works or not depends on what your ExecuteCommandLine method does with teh data you pass it: myself I'd pass it two strings - one the exe and the other the parameters and use the Process.Start overload that takes two parameters instead: MSDN[^]
这篇关于如何在c#中使用out space执行命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!