1

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)

3
  • 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
    Commented Feb 6, 2014 at 13:02
  • Try to use variable names it helps to diagnose.. so do str="...."
    – barlop
    Commented Feb 6, 2014 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
    Commented Feb 7, 2014 at 2:54

3 Answers 3

1

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: https://stackoverflow.com/questions/486087/how-to-call-an-external-program-with-parameters

1
  • Can you provide a little example? CreateProcess syntax is a big mess for me...
    – bartimar
    Commented Feb 6, 2014 at 15:59
0

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);
0

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

1
  • Did you even read the question? I want to pass the path to executable and argument with spaces to system() function...
    – bartimar
    Commented Feb 10, 2014 at 11:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .