views:

43

answers:

2

I'm using process::start(PATH); to open up the process. The problem is, sometimes it finds the file and sometimes it doesn't.

For example, this works:

process::start("C:\text.exe");

But this doesn't work:

process::start("C:\New Folder\text.exe");

Any idea what the difference is?

+4  A: 

You have to escape the \ characters.

In a C string \t is the TAB character. Use:

process::start("C:\\New Folder\\text.exe");
paxdiablo
That was my first thought, but then why is "C:\text.exe" working? It should turn into `C: ext.exe`
Michael Mrozek
Yes, it will. And if you type in `c: ext.exe` (or even `c: blah blah blah`) at the command line, you'll find out it doesn't give you an error. I'm not sure how OP is defining "success" but if it's just "no error generated", that would explain it.
paxdiablo
@pax Oh, of course. So it's probably a combination of this and [Saxon's answer](http://stackoverflow.com/questions/3436857/c-process-start-problem-with-path/3436875#3436875) about escaping spaces
Michael Mrozek
ok thanks :)))))))
Ramiz Toma
+2  A: 

The library might think that c:\New is the program you are running, and Folder\text.exe is an argument you are passing to it.

You might need to quote it, so you're calling this:

"C:\New Folder\text.exe"

Which as a C++ string would look like this:

process::start("\"C:\\New Folder\\text.exe\"");
Saxon Druce