below code is executed but not opening my mac os terminal on my colleague machine and returing exit code as 1 instead of 0
Runtime runtime = Runtime.getRuntime();
String output= "";
String[] myCommand = null;
if(command.equals("open")) {
String[] openTerminal = new String[] {
//"/bin/bash", "-c",
"osascript -e 'tell application \"Terminal\" to do script \"" +
"echo Welcome to Tectonic" +"\"'"
};
myCommand = openTerminal;
}
try
{
Process p = runtime.exec(myCommand);
InputStream stdIn = p.getInputStream();
InputStreamReader isr = new InputStreamReader(stdIn);
BufferedReader br = new BufferedReader(isr);
String line = null;
int exitVal = p.waitFor();
if(exitVal==0) {
}
You'll see the error message if you add this after exec
:
p.getErrorStream().transferTo(System.out);
Or merge stderr to stdout:
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Process process = pb.start();
process.getInputStream().transferTo(System.out);
int rc = process.waitFor();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.