Post-export Shell Command doesn't work with: sh myScriptFile.sh

Hello,
I can’t find the way how to launch sh file from Post-export Shell Command in Projucer.

When I try to do that from terminal I have no problem, everything works fine.
I can run on many ways:
./myScript.sh
or
sh myScript.sh
or
bash myScript.sh

And as I told from terminal everything works fine, but when I write such command in Projucer Post-export Shell Command(macOS, Linux) I get error:

Shell command: /bin/sh -c bash myScript.sh failed with code: 127

I also tried that:
sh %%1%%/Scripts/GetCurrentBranchName.sh

Then I get no error but the script is not executed it just looks like nothing happens.
For any help great thanks in advance.

Best Regards

Have you tried a full path to the script?

Hmmm…
As I understand this is full path:
%%1%%/Scripts/GetCurrentBranchName.sh

But of course I also tried:
/Users/me/Development/myProject/Scripts/GetCurrentBranchName.sh

But I end up with exactly same result. Just doesn’t work.

What OS are you running… see:

It seems PJ is not using the environment PATH

Rail

I analyzed your error and responses carefully and it looks like you typed those variant:

bash myScript.sh
bash %%1%%/Scripts/GetCurrentBranchName.sh
bash /Users/me/Development/myProject/Scripts/GetCurrentBranchName.sh

Error code 127 suggests that command is not found, so I guess the problem is with “bash” part.

Two options come to my mind:

  1. you can type full path to bash, probably /bin/bash or /usr/bin/bash (you can check that with which bash in terminal).

  2. you skip bash and leave only path to script. You can add shebang in the first line of your script and set it to bash (Shebang (Unix) - Wikipedia)

Great thanks for your help Szemek, but nothing help.
I tried all your suggestions, and I get rid of “failed with code: 127”, now there is no error, but the script is just not executed.

Hello,
I finally find out what was wrong. Unfortunately my script was wrong :slight_smile:
That script worked only if it was launched from directory where he is. But from any other directory not.

So now inside my sh file I use absolute path to all files and commands.
I get that absolute path by:
MYDIR="$( dirname "$( which "$0" )" )"

Now everything works fine, great thanks for your help.