|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.paneris.util.SystemUtils
public class SystemUtils
This class contains a number of static functions to run commands in new processes
Constructor Summary | |
---|---|
SystemUtils()
|
Method Summary | |
---|---|
static java.lang.String |
exec(java.lang.String cmd)
Execute a system command and return its ouput in a String. |
static java.lang.String |
execAsScript(java.lang.String script,
java.lang.String scriptName)
Write a command to a script and then execute that script. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SystemUtils()
Method Detail |
---|
public static java.lang.String exec(java.lang.String cmd) throws java.io.IOException
It works by forking a separate process and capturing it's output stream (which is a java.lang.io.InputStream!)
Note that at present we ignore any InterruptedException which might get thrown whilst we are waiting for the process to terminate
cmd
- System command to execute
java.io.IOException
- if there is a problem reading from
the process' output streamInputStream
,
Process
public static java.lang.String execAsScript(java.lang.String script, java.lang.String scriptName) throws java.io.IOException
If the script is not executable then this will fail silently. IT IS UP TO YOU TO MAKE THE FILE EXECUTABLE ON YOUR SYSTEM. YOU MUST ALSO MAKE THE CMD AN APPROPRIATE SCRIPT
TODO - can we chmod in Java?
script
- text of a script to executescriptName
- the filename to write the script to. The file should
be executable (you might want to create it before hand
and change permissions outside of java)
java.io.IOException
- if there is a problem reading from
the script's output stream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |