Serious Commandline Issue

Currently JuceApplication passes the command line as one string, which is concatenated from the argv[] values. This has serious issues with commandline arguments that are quoted. It is currently impossible to pass arguments with spaces in them:

Instead of passing a single string to the JuceApplication (which has the quotes removed, btw), a StringArray would be more appropriate. That would keep the arguments parsed by the OS shell separate until they are processed by the app. It will also save us the effort of parsing that one string back into pieces.

Not something that would be difficult to change, even with a lot of deployed products, IMO. Any chance this will make it into the code base?

Nor sure if this warrants the word “serious”! The StringArray class has a tokeniser that will understand the quotes and give you the correct result. That’s what I use.

Anyway, I think I did it this way because on win32 (or some OS, I forget…) the command line doesn’t arrive via the normal main() parameters, so I made everything use the lowest-common-denominator format, which is just one big string.

I tried that already but the quotes aren’t there anymore, because the shell removed them (Mac). It is impossible to guess where the quotes may originally have been, so as it is now, it is impossible to pass filenames as arguments (most of them have spaces).

Files being the most common argument to any program, this is breaking the purpose of commanline arguments altogether.

For Windows, main() could use the tokeniser to create the StringArray.

in juce_Application, line 256, it makes sure that quotes are added if necessary. So how did you manage to avoid that?

There’s nothing special in line 256. Which tip are we talking about? I thought I have the latest (not the modules branch, though).

Well, please have a look at the modules branch!

[quote=“jules”]Nor sure if this warrants the word “serious”! The StringArray class has a tokeniser that will understand the quotes and give you the correct result. That’s what I use.

Anyway, I think I did it this way because on win32 (or some OS, I forget…) the command line doesn’t arrive via the normal main() parameters, so I made everything use the lowest-common-denominator format, which is just one big string.[/quote]

There is a function that does the splitting automatically on windows – here is the patch I’m using in order to retrieve command lines args as a string array instead of a single string:

int argc; LPWSTR *szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &argc); StringArray argv; for (int i=1; i < argc; ++i) argv.add(szArglist[i]);

I would love to do so, but I don’t think this is advisable in the middle of a project. How mature is the modules branch right now? Is it safe to make the move already?

the module branch is ready and safe! ( and its better to change in the middle of a project as at the end :wink: )