Created
May 17, 2018 12:32
-
-
Save datacorner/d22e134ea74814810c81247f50fc778a to your computer and use it in GitHub Desktop.
Execute a commande line in synchronous call mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute a commande line in synchronous call mode | |
* @param line command line | |
* @return result | |
*/ | |
public String EXECUTE_CMD(String line) { | |
String retValue = ""; | |
try { | |
if (!line.equalsIgnoreCase("")) { | |
Process p = Runtime.getRuntime().exec(line); | |
try { | |
JoyReadStream s1 = new JoyReadStream("stdin", p.getInputStream()); | |
//ReadStream s2 = new JoyReadStream("stderr", p.getErrorStream ()); | |
s1.start(); | |
//s2.start (); | |
p.waitFor(); | |
retValue = s1.getCmdreturn(); | |
} catch (InterruptedException e) { | |
retValue = e.toString(); | |
} finally { | |
if (p != null) p.destroy(); | |
} | |
} | |
} catch (IOException ex) { | |
retValue = ex.toString(); | |
} | |
return retValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment