I'm trying to invoke an apple script from the java code,
The issue is that the script runs a-synchronically, while I need it to
run synchronically.
I'm using:
Process p = Runtime.getRuntime().exec(i_cmdLine);
retVal = p.waitFor();
the waitFor() returns after the script was started to run,
but it doesn't wait for the for the script to be completed.
I need some indication to know when the apple script completed its
work.
(in my case the script is generating some files, so I need to know
when
the files where generated)
You will have to post what i_cmdLine contains. When I run the code:
public class TestOSA {
private static final String[] COMMAND = {
"osascript",
"-e",
"tell application \"Finder\" to return display dialog \"Hello world!\""
};
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
Process p = null;
try {
p = rt.exec (COMMAND);
p.waitFor();
}
catch (Throwable t) {
t.printStackTrace();
}
System.err.println ("Done!");
}
}
it waits for the osascript command to complete.
Also, note that the above is not production-quality code. Whenever
one uses Runtime.exec one should always spawn two threads to drain
the stout and stderr streams, *especially* when calling
Process.waitFor. Failure to do so will result in a deadlock if the
process generates more than a couple of hundred bytes of output. I do
not see this in your posted code, I assume you removed it for
brevity. I also am assuming that your variable i_cmdLine is of type
String[], and not just String. Using the scalar String overloading of
Runtime.exec can easily get you into trouble when it parses the
string differently than what was expected.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden