Problem executing a native method Friday, 02-Jul-1999 09:23:54 12.25.1.122 writes:I am unable to successfully get my java app to execute a unix command. I am trying to use the Process and Runtime classes to do this. The code looks like:
public void actionPerformed(ActionEvent e) {
...
Process list;
BufferedInputStream dirlist;
try {
list = Runtime.getRuntime().exec("date");
dirlist = new BufferedInputStream(list.getInputStream());
} catch(IOException b) {
System.err.println("Cannot start date");
}
. . .
}
When I press enter after typing in a JTextfield, the system error "Cannot start date" is written to the terminal window.
Ideally, I would like run a ksh script, but I am first trying to run a simple unix command which returns stdout to display within my app......help,pleeaase?
Derek
Re: Problem executing a native method Sunday, 04-Jul-1999 05:30:07 171.215.210.201 writes:The exec() command is used to run files. As far as I know it cannot execute system commands in the way that you are attempting to. In DOS, you wouldn't be able to run "dir" for a directory listing. You would have to invoke the function from the interpreter. So, to execute the directory llsting in DOS, the command is "command.com /c dir". There may be an equivalent in UNIX.
MikeD