Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a similar problem like this How do I escape spaces in command line in Windows without using quotation marks?

But it seems I can't use the carets

C:\>C:\Program^ Files^ (x86)\Adobe\Reader^ 11.0\Reader\AcroRd32.exe
C:\Program Files is not recognized as an internal or external command, operable program or batch file.

cd works fine:

C:\>cd C:\Program^ Files^ (x86)\Adobe\Reader^ 11.0\Reader\
C:\Program Files (x86)\Adobe\Reader 11.0\Reader>

I'm calling the Adobe Reader from C++ App with

UniString cmd("\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" ");
system(cmd.ToCStr());

This is OK, Adobe reader started. But when I add another escaped quotes to pass the argument path to pdf

UniString cmd("\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" \"");
cmd.Append("A\\B with space\\C\\test.pdf");
cmd.Append("\"");
system(cmd.ToCStr());

I got

C:\Program is not recognized as an internal or external command, operable program or batch file. 

What is going on here? Why can't I use the carets or escaped quotes more times?

(Geez, I hate windows so much)

share|improve this question
    
well, i'd note that CD works even without the carets(and without quotes). so, how can carets escape spaces or how can space be escaped without quotes. hope we find out! –  barlop Feb 6 at 13:02
    
Try to use variable names it helps to diagnose.. so do str="...." –  barlop Feb 6 at 13:06
    
I notice in the answer to this question, there is an example where caret escapes space superuser.com/questions/279008/… `C:\>c:\Documents and Settings\a.bat 'c:\Documents' is not recognized as an internal or external command, operable program or batch file. C:\>c:\Documents^ and^ Settings\a.bat <-- displays what it should i.e. executes. –  barlop Feb 7 at 2:54

3 Answers 3

I believe you should use the CreateProcess() function rather than launching the cmd.exe program and then telling it to run acrobat.

Its more complicated to set up but you don't need to pass through cmd's admittedly odd command line handling.

update: I just took a quick look as someone else had a similar question which provides an answer which may help: http://stackoverflow.com/questions/486087/how-to-call-an-external-program-with-parameters

share|improve this answer
    
Can you provide a little example? CreateProcess syntax is a big mess for me... –  bartimar Feb 6 at 15:59
up vote 0 down vote accepted

I solved it:

for system() I had to use two escaped quotes

UniString cmd("\"\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" \"D:\\Second Path\\Foo\\Bar\"\");
system(cmd.ToCStr());

or better with WinExec()

UniString cmd("\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" \"D:\\Second Path\\Foo\\Bar\");
WinExec(cmd.ToCStr(),SW_SHOW);
share|improve this answer

Enclose the entire string with double quotes, like so: "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"

share|improve this answer
    
Did you even read the question? I want to pass the path to executable and argument with spaces to system() function... –  bartimar Feb 10 at 11:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.