对于AppleScrip命令,进程退出代码返回为1,并且在MacOS中未打开终端(发生在其他PPL系统上)

dsekswqp  于 2022-10-17  发布在  Mac
关注(0)|答案(1)|浏览(151)

执行了以下代码,但没有在我的同事机器上打开我的mac os终端,并将退出代码恢复为1而不是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) {

        }
rjjhvcjd

rjjhvcjd1#

如果在exec之后添加以下内容,您将看到错误消息:

p.getErrorStream().transferTo(System.out);

或将stderr合并到stdout:

ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Process process = pb.start();
process.getInputStream().transferTo(System.out);
int rc = process.waitFor();

相关问题