E
ezjlxp
I'm trying to use Java's Runtime.exec() to call some unix commands in
an uninstaller. For reasons I don't have time to explain, making a
call to a shell script which executes the unix commands isn't an
option.
In the uninstall process i'm trying to execute the follow unix
compound command:
rmdir /directory >> /tmp/uninstall.log 2>&1
if I run this command from a terminal it runs as expected. If the
directory isn't empty it prints a message to the uninstall.log file.
However, when I try to pass this into the exec command it never writes
the error message to the log file when the directory is not empty.
I read that if there is a space in an argument of a command that you
need to put the command into an String array instead of a string.
Therefore I tried the following with no luck:
Process p = new Process();
....
String[] cmd = new String[]{"rmdir", "/directory", ">>", "/tmp/
uninstall.log", "2>&1";
p = Runtime.getRuntime().exec(cmd).waitFor();
is that the correct way to split up the command to put it into the
String array?
I have a hand full of other commands I am calling in the same way.
All of them execute the Unix command as expected but if any of them
fun into an error, will not print the error message to the
uninstall.log file.
Any help would be greatly appreciated. Thank you!
-Jared
an uninstaller. For reasons I don't have time to explain, making a
call to a shell script which executes the unix commands isn't an
option.
In the uninstall process i'm trying to execute the follow unix
compound command:
rmdir /directory >> /tmp/uninstall.log 2>&1
if I run this command from a terminal it runs as expected. If the
directory isn't empty it prints a message to the uninstall.log file.
However, when I try to pass this into the exec command it never writes
the error message to the log file when the directory is not empty.
I read that if there is a space in an argument of a command that you
need to put the command into an String array instead of a string.
Therefore I tried the following with no luck:
Process p = new Process();
....
String[] cmd = new String[]{"rmdir", "/directory", ">>", "/tmp/
uninstall.log", "2>&1";
p = Runtime.getRuntime().exec(cmd).waitFor();
is that the correct way to split up the command to put it into the
String array?
I have a hand full of other commands I am calling in the same way.
All of them execute the Unix command as expected but if any of them
fun into an error, will not print the error message to the
uninstall.log file.
Any help would be greatly appreciated. Thank you!
-Jared