It is very small but tricky, just try it
public static int executeWithInput(String cmd) throws Exception
{
int retCode = 0;
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
OutputStream out = pr.getOutputStream();
out.write('y');
out.write('\n');
out.flush();
pr.waitFor();
retCode = pr.exitValue();
return retCode;
}
2 comments:
this code seems to be not working ...
Whats the issue you are facing ?
Please provide your sample code, for debugging.
Post a Comment