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.
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
(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?
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
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.
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?