/*
* This code is Copyright Matthew McGee
* email@hidden
*
*/
/*
* Author : M. McGee email@hidden 9/04/2003
* This class allows you to execute any command as that user.
* Although the name suggests Unix it should run fine under any platform.
*/
package server;
import java.io.*;
public class RunUnixCommand {
private String input;
public RunUnixCommand() {
}
public RunUnixCommand(String command) {
runCommand(command);
}
public String runCommand(String command) {
String data = "";
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
byte[] b = new byte[bis.available()];
bis.read(b,0,bis.available());
input = new String(b);
} catch (InterruptedException ie) { ie.printStackTrace();
} catch (java.io.IOException ioe) { ioe.printStackTrace();System.out.println("Problem running command "+command); }
return input;
}
public static void main(String args[]) {
if (args.length == 1) {
RunUnixCommand ruc = new RunUnixCommand();
System.out.println(ruc.runCommand(args[0]));
} else { System.out.println("Syntax : java RunUnixCommand command"); }
}
}
If I understand the issue, you are trying to execute a native
application
and it is hanging. It could be process.waitfor. If I got the problem
correct
try the following code.
On Oct 5, 2004, at 2:46 PM, Greg Guerin wrote:
David Rocks <email@hidden> wrote:
I have run into more problems. When I try to run osascript through
runtime.exec in a java program it appears to go into la-la land. I see
no activity, and it also appears that the interface is hung.
Use 'kill -QUIT pid' to get a thread-dump from the wedged Java app.
Not the behavior using the open command or calling the browser
directly. There I can see trace records everytime I call the plugin.
The
call statement looks OK in the trace. And I have no problem with
identical calls in the apple script editor or issuing the commands in
the terminal shell. Is there something different about the way
osascript
is executed when called from within a program?
Exactly what command and args is being exec()'ed?
Is any output produced on stdout or stderr?
Exactly what is the command and args when the exec() works?
-- 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
email@hidden
Instructor, GCA Hampton, Va.
------------------------------------------------------------------------
-------------------------------------
Work is the curse of the drinking classes.
-- Mike Romanoff
_______________________________________________
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