Mark
asked on
Is there a way to run "native" commands from jsp?
I have tomcat 6.0 on linux. Is there a way to run native commands such as "ls > ls.out" or whatever?
I don't believe that will work. Runtime.exec() is NOT a command line. The following article explains why:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
(It's written in the context of Windows, but it applies to Linux as well.)
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
(It's written in the context of Windows, but it applies to Linux as well.)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I went ahead and tried the piping command and, as predicted, it didn't work. I also tried Runtime.getRuntime().exec( "/bin/sh -c 'echo Howdy | /usr/bin/mail -s testing me@mydomain.com' >/dev/null 2>&1"); and that didn't work either; which was frankly surprising. Perhaps the stdout/stderr redirects messed it up. I removed those, but the return status was '2', and no message was sent. I may experiment further. I'll have to look up the '2' status.
However, putting it all in a shell script did work fine.
However, putting it all in a shell script did work fine.
Right -- if you look at the article malfunction84 gave in a post above, you'll see the explanation. You can't redirect stderr and stdout -- you have to handle them programmatically in your Java program. So doing "/bin/sh -c 'xxxxx'" is fine, but >/dev/null is not.
Process p = Runtime.getRuntime().exec(