A problem running a shell script

I have a shell script in a folder on my hard drive. This script runs a java application and then returns its results. If I execute it from a terminal session (sh go.sh) and am in the same folder as the script it works fine.

Using applescript, If I "do shell script “/full/path/go.sh” using the same bash script, java returns an error saying it cannot find the javac compiler or the class main file.

This must be a path error??
I am a bit lost as I see that the “unable to find file” message is a path error, but I don’t know how to instruct applescript to set the path for the bash script.

Max

Hi,

without knowing the actual path it’s very hard to answer this question…

Stefan,

Quite right…that was vague. It’s a struggle for me to describe some of this. Be warned that I am complete beginner!

The path to the bash script folder; /Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/go.sh
ls for that folder ; IMG_3627.jpg Softek libbardecode.dylib sample.class go.sh libbardecode_jni.dylib sample.java

the script “go.sh”;

#!/bin/sh
set -x
#javac /Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/sample.java
DYLD_LIBRARY_PATH=. export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=. export LD_LIBRARY_PATH
CLASSPATH=$CLASSPATH:. export CLASSPATH
java sample

(Line 3 is commented out as it was a lazy way to ensure the class file was ready.)

When in terminal and having cd’d into the folder- /Users/accounts/Downloads/bardecoder_7_3_1b_osx/java; (as above)
I can enter sh go.sh and it works perfectly. No error messages and the decoded barcode value is returned.

If I now go into an applescript and run “do shell script /Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/go.sh”
i get

Result:
error "+ DYLD_LIBRARY_PATH=.

  • export DYLD_LIBRARY_PATH
  • LD_LIBRARY_PATH=.
  • export LD_LIBRARY_PATH
  • CLASSPATH=:.
  • export CLASSPATH
  • java sample
    Error: Could not find or load main class sample" number 1

Is that the data you need?? If not, is there a format for reporting error’s I could use?

Thank you for looking at this.

Max

I suspected there was a space character in the path but the path seems to be correct.

Anyway try to escape the path with quotes

do shell script quoted form of "/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/go.sh"

Hello Stefan.

Sorry,did not work.

I run the 1 line applescript do shell script “/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/go.sh”
the final line can be either

java sample
or
java “/Macintosh HD/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/sample.java”
or
java /Macintosh HD/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/sample.java

i get
Error: Could not find or load main class “.Macintosh” number 1

Here’s the bash script again

#!/bin/sh
set -x
#javac “/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/sample.java”
DYLD_LIBRARY_PATH=. export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=. export LD_LIBRARY_PATH
CLASSPATH=$CLASSPATH:. export CLASSPATH
java

This is clearly an error returned from JAVA, not applescript?

Max

If

/Macintosh HD/Users/accounts/Downloads/bardecoder_7_3_1b_osx/java/sample.java

is a standard POSIX path it cannot start with / because the leading slash represents the startup volume.

Thanks,

Just did that and I’m back to the same error messages, “file not found, could not find or load…”.

I am mystified as it works perfectly when i am in terminal. Running in terminal, the shell script is using the same environment variables as when run from an applescript.
But when run in Applescript JAVA says that it CANNOT find the files.

The various lines in the shell script setting the environment are OS X and I suspect it’s something there that is wrong.

Should i be setting paths in the applescript before i run the shell script? It is saved in the same directory as the go.sh script.

Max

Stefan,

I am getting myself muddled trying to write an Applescript to call a shell script, to call a JAVA script.
I am not a coder and can just about follow the pseudo english of applescript.

The OS X and Java syntax are very difficult for me, and I only want to run one application with one set of parameters.

Would it be possible to set the class path and path variables using Applescript? There must be a way for Applescript to talk to the shell? I could then call the JAVA routine directly from Applescript?

Max

Hi Stefan

Worked it out.

I have a single line applescript do shell script “cd (path to the Java class file) ; java class file”

Dumping the intermediate bash.script and using applescript to manage java is simple for me to write.

Stefan, thanks for advising me.

Max