Skip to content

Instantly share code, notes, and snippets.

@datacorner
Created May 17, 2018 12:32
Show Gist options
  • Save datacorner/d22e134ea74814810c81247f50fc778a to your computer and use it in GitHub Desktop.
Save datacorner/d22e134ea74814810c81247f50fc778a to your computer and use it in GitHub Desktop.
Execute a commande line in synchronous call mode
/**
* 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