Matthew McGee wrote:
> public RunUnixCommand(String command) {
> runCommand(command);
> }
Quoting will not work when the command is expressed as only a single
String. See the API docs for exec(String).
You either need to use a String[], or you need to feed the quote-bearing
String to 'sh', for it to parse and execute (in a platform-dependent
manner). See 'man sh', in particular the -c option.
> Process p = Runtime.getRuntime().exec(command);
> p.waitFor();
> BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
This will deadlock (hang) if the child Process produces more bytes on its
stdout stream than will fit into a single pipe buffer. I forget how big a
pipe's buffer is on Mac OS X, but it's probably something like 512 bytes to
4KB. Some commands have output that will fit into the pipe's buffer, but
many more do not.
If the Process can product output, you have to spawn a Thread to read the
stream. You have to do the same on the stderr stream, too, or you must
ensure that stderr produces no output.
There is an example of running a child Process in my open source Humble
Narrator:
<http://www.amug.org/~glguerin/sw/#narrator>
See the class Humble.java. It even runs 'osascript' in one option.
The Humble class is not completely general-purpose, because it relies on
how 'osascript' can be told to produce output only on stdout or on stderr.
This was a reasonable simplification, given the circumstances, but it
definitely will NOT work in the general case.
-- GG
_______________________________________________
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
This email sent to email@hidden