Issue with ChildProcess and space character in argument


#1

Hi Jules,

 

If you use a command line containing a path with space characters (using the StringArray interface) it doesn't work.

I've checked the recent commit

http://sourceforge.net/p/juce/code/ci/335084c542d69685cbcb23a9ff0de85c0615e568/#diff-1

and it doesn't do the right thing either.

Something like that works fine for me FWIW


bool ChildProcess::start (const StringArray& args, int streamFlags)
{
    String escaped;
    for (int i = 0; i < args.size(); ++i)
      escaped << args[i].quoted() << ' ';
    return start (escaped.trim(), streamFlags);
}

The current code works fine on OSX FWIW

 

Any idea ?

 

Thanks,


#2

But that'd break in many cases.. Not all apps will be smart enough to strip quotes off every one of their arguments if they're expecting simple flags. And if the arguments already contain a quote, it'll also fail. That's why I used escape characters instead.

What exactly are you giving it that's failing?


#3

I've fixed my comment and the title. I meant space and not escape character. My bad.

I'm using the unrar command line application to extract a rar file to a directory which contains a space character.


#4

Can you give me a snippet that would let me quickly reproduce and test this?


#5
File appDir = File::getSpecialLocation(juce::File::currentApplicationFile).getParentDirectory();
File pathToARarFile;
File pathToADirectoryWithASpace;


String rarExe = appDir.getChildFile("UnRAR.exe").getFullPathName();

StringArray commandLine;

commandLine.add(rarExe);
commandLine.add("x");
commandLine.add("-y");
commandLine.add(pathToARarFile.getFullPathName());
commandLine.add(pathToADirectoryWithASpace.getFullPathName());

ChildProcess process;
process.start(commandLine);

 

You can grab WinRar Here

http://www.rarlab.com/rar/wrar51b2.exe
 


#6

Sorry - I actually just fixed this a few minutes ago anyway. (I think!)

I read up on how the official win32 functions handle parsing quotes and spaces, so it should be correct now.


#7

Humm it do not seems to work.

Don't know much what's happening


#8

Well.. I followed all the best-practice advice I could find about how to escape the arguments. Unlike unix though, it's not guaranteed that all apps will respond to this stuff in the correct way.


#9

No biggie.

I currently concatenate stuff myself for Windows using quoted arguments and it works fine.

Thanks !