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
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. 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
@ 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 @)
Also, if your apppath
contains spaces, then you should surround the entire string with " characters
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.