简体   繁体   English

参数没有传递到命令提示符

[英]Arguments are not passing into command prompt

string appPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

Process p = new Process();
p.StartInfo = new ProcessStartInfo("cmd.exe", @"/c opencvproject.exe " + @appPath + @"\\bin\\Debug\\center\\centerilluminate.jpg");

p.Start();

I tried this at my other computer and it works , however when I tried it in my new computer this doesn't work somehow. 我在另一台计算机上尝试过该方法,但是它可以正常工作,但是当我在新计算机上尝试该方法时,它不起作用。 Anyone knows how to solve this? 有人知道如何解决吗? The program I am using is c# and im calling cmd to call c++ program which is opencvproject.exe 我正在使用的程序是c#和im调用cmd来调用c++程序,该程序是opencvproject.exe

There are still multiple instances where I use cmd to trigger other c++ program and python scripts to run and those are not working too. 仍然有多个实例,我使用cmd来触发其他c++程序和python脚本运行,但这些实例也无法正常工作。 I am not sure what am I doing wrong.. 我不确定我在做什么错..

Hold the path between double quotation. 保持双引号之间的路径。

p.StartInfo = new ProcessStartInfo("cmd.exe", "/c opencvproject.exe \"" + appPath + "\\bin\\Debug\\center\\centerilluminate.jpg\"");

Explanation 说明

Character combinations consisting of a backslash () followed by a letter or by a combination of digits are called "escape sequences." 由反斜杠()后接字母或数字组合组成的字符组合称为“转义序列”。
http://msdn.microsoft.com/ja-jp/library/h21280bw.aspx http://msdn.microsoft.com/ja-jp/library/h21280bw.aspx

@ makes escape sequence no effect, so.. @使转义序列无效,所以..

var s1 = @"\\bin\\Debug\\";  // This contains wrong path \\bin\\Debug\\
var s2 = "\\bin\\Debug\\";   // This contains right path \bin\Debug\

And need using escape sequence to hold the double quotation between double quotation. 并且需要使用转义序列在双引号之间保持双引号。

var s3 = "\"\\bin\\Debug\\\"";  // This contains "\bin\Debug\"
var s4 = @"\"\\bin\\Debug\\\"";  // compile error 

The @ character automatically escapes characters in the string behind it, so you shouldn't double backslash your path. @字符会自动将其后面的字符串中的字符转义,因此您不应该在路径中使用双反斜杠。

Eg, where you have: 例如,您在哪里:
@"\\\\bin\\\\debug\\\\.."

it should either be: 它应该是:
@"\\bin\\debug\\..."

or: 要么:
"\\\\bin\\\\debug\\\\.." (without the @) "\\\\bin\\\\debug\\\\.." (不带@)

Also, if your apppath contains spaces, then you should surround the entire string with " characters 另外,如果您的apppath包含空格,则应在整个字符串周围加上“个字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM