-1

This is driving me crazy. After a lot of tests, I managed to successfully run the following .sh file in the terminal and it worked perfectly as I expected.

adt -package -target apk -storetype pkcs12 -keystore $AND_CERT_FILE -storepass $AND_CERT_PASS "$OUTPUT" "$APP_XML" -C bin . -C icons/android . -extdir lib .

echo "DONE";

I want to run this from PHP not the terminal, so I wrote the following in PHP to call the .sh file but although PHP returned the "DONE" message, the command does not work. If I mistype the command, no errors are shown. Here's what I wrote in PHP:

$output = shell_exec("./test.sh");
echo $output;

Does anyone have any ideas?

Ben
  • 51,770
  • 36
  • 127
  • 149
Peyman
  • 367
  • 1
  • 4
  • 11
  • Aren't you running your LAMP server with Safe Mode on? See **Notes** http://php.net/manual/en/function.shell-exec.php – Marek Sebera Aug 05 '12 at 12:03
  • Is the path to your script set absolutely right? – Marek Sebera Aug 05 '12 at 12:11
  • @Geoffrey I get(/usr/local/bin:/usr/bin:/bin) when I echo passthru('echo $PATH'); from php and I get (/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-i386/bin:/home/hadi/Public/sdk/flex_sdk_4.5.1.21328/bin:/home/hadi/Public/sdk/android/platform-tools ) when I do so from terminal – Peyman Aug 05 '12 at 12:38
  • @MarekSebera My safe_mode = Off, should it be on? – Peyman Aug 05 '12 at 12:45
  • Does your script have a shebang line? – tripleee Aug 05 '12 at 12:52
  • You might include a reference to the purpose of `adt` - it looks like the Adobe AIR packager – Henk Langeveld Aug 05 '12 at 12:59
  • Where is the `adt` executable located? It is usually best to use absolute paths in situations like this. Also, keep in mind that the shell environment in which PHP executes is often not the same as your own shell environment, i.e. environment variables such as PATH may not hold the same values. – rexmac Aug 05 '12 at 15:04

1 Answers1

0

You cannot mix options with non-option arguments.

The proper format is:

command [-options ...] [--] [non-option arguments]

Any word not starting with - will end option processing, as will a bare -- (optional). All arguments after that won't be processed as options.

The arguments "$OUTPUT" and "$APP_XML" belong at the end of the line, or are missing the proper option prefix for adt(I leave that as an exercise).

adt -package -target apk -storetype pkcs12 \
    -keystore $AND_CERT_FILE \
    -storepass $AND_CERT_PASS \
    -C bin . \
    -C icons/android . \
    -extdir lib . \
    "$OUTPUT" "$APP_XML"

Note that I submitted an edit of the original code with the line broken down here. Before the edit I had no clue, whatsoever. While adding the \ newline pairs, the issue became obvious.

Take a look at this adt packaging troubleshooting blog entry. It appears to confirm my suspicion. The blogger explicitly warns to specify any filenames last.

Henk Langeveld
  • 8,088
  • 1
  • 43
  • 57
  • Generally, editing questions to change the code therein is a bad idea as it is all too easy to change the meaning. Answering, or commenting, as you've done here is better. You also don't need to add HTML comments. – Ben Aug 05 '12 at 12:46
  • 1. I'm very careful to not change the original behaviour of the code. 2. I added the html comments as adding newlines and fixing typos does not always get an edit beyond the 6 char limit. Otherwise I agree entirely. Editing a code sample should not be done frivolously. – Henk Langeveld Aug 05 '12 at 12:49
  • I messed type the first .sh file here is the one I am working with. adt -package -target apk -storetype pkcs12 -keystore $AND_CERT_FILE -storepass $AND_CERT_PASS "$OUTPUT" "$APP_XML" -C bin . -C icons/android -extdir lib . – Peyman Aug 05 '12 at 13:08
  • Hi @Peyman, Can you correct the question, and while you're at it, break the lines like in my answer? It improves readability tremendously. I already submitted an edit for your question to break up the lines. – Henk Langeveld Aug 05 '12 at 13:12