[SOLVED] Windows post-export shell command

How do you get anything to work in the Projucer post-export shell command? I’ve tried running a batch file with a .bat and .cmd extensions and even the most trivial commands fail e.g. a batch file containing echo hello fails with exit code 1.

The command i’ve put to the text box is

"%%1%%\Tools\apply-patch.cmd"

And according to the error dialog the path is expanded correctly, but the exit code is always 1.

If i put echo hello directly to the text box in Projucer it succeeds.

The command i’m actually trying to run is

"C:\Program Files\Git\usr\bin\patch.exe" -d "%%1%%" -s -p0 < "%%1%%\Patch\jucelookandfeel.patch"

or

"C:\Program Files\Git\usr\bin\patch.exe" -d C:\Users\matti\Code\git\Kairatune -s -p0 < C:\Users\matti\Code\git\Kairatune\Patch\jucelookandfeel.patch

This works fine when ran directly in the command prompt. I’ve tried various different ways to quote the command, but haven’t come across any that’d work.

How’s the post-export shell command supposed to work?

Bump.

Haven’t been able to get this to work. I’ve given up on the batch file, since i can’t get the patch command to work, even when i put it directly to the text box.

I’ve tried just about everything, including using progra~1 to eliminate any spaces from the path and using slashes instead of back slashes in paths and pretty much every possible combination of quotes and double quotes. Nothing seems to work. The exact same command line (with or without the initial cmd /c that appears in the error message, succeeds if i enter it into a command prompt, but Projucer fails with error code 1.

Error code 1 seems to result when a command isn’t found. Why does Projucer fail with a command like C:\Program Files\Git\usr\bin\patch.exe --help? In a Command Prompt the command outputs the help message and exits with zero i.e. %ERRORLEVEL% is zero.

There must be something fundamental i’m missing here. Surely a lot of devs use the post-export shell command all the time. Please help if you know anything about this.

Ok, i figured this out - at least partly - and it’s weird.

The post-export shell command fails if there are any quotes in the string. A batch file works fine, as far as you don’t put the path in quotes in the text box e.g.

%%1%%\Tools\apply-patch.cmd

If you need to reference a path with any spaces in it, you must use a batch file as the Projucer text box simply must not contain any quote characters - single nor double.

I don’t know what would happen if the %%1%% would contain any spaces.

hm, my simple .bat files working fine with the quotes in the string
copy /b “A:\Builds\VisualStudio2019\x64\Release\Standalone Plugin\name.exe” . /y

seems 1st command must be without quotes, so non quoted comman like call may be used
call “C:\Program Files\Git\usr\bin\patch.exe” -d C:\Users.…
or some kind of.

Paths can be quoted normally in a batch file. The command string in the text box can’t contain quotes for some reason. This can be confusing as the macOS/Linux post-export shell command text box can contain quotes.

I just hit this and it’s particularly a problem if the %%1%% path has a space.

The problem is the Producer code in ProjectSaver::runPostExportScript() treats the string as an argument (last part in a StringArray) that’s passed to ChildProcess to run the command. ChildProcess then does a bunch of sanitizing to the argument like wrapping the whole thing in quotes if there’s a space in there. If there’s already quotes or the command won’t work as a quoted string it breaks.

I’ve changed my ProjectSaver::runPostExportScript() to just grab the command string as a string, prepend cmd.exe /c (for windows), and pass it all through to ChildProcess just as a string. Where to put quotes, correct slashes, etc. is now up to me to get right.

Might not be the fix for everyone but works for me.

1 Like