Tag: runtime.exec

ProcessBuilder和Runtime.exec()之间的区别

我试图从java代码执行一个外部命令,但是我注意到了Runtime.getRuntime().exec(…)和new Process(…).start()之间的区别。 使用Runtime : Process p = Runtime.getRuntime().exec(installation_path + uninstall_path + uninstall_command + uninstall_arguments); p.waitFor(); exitValue为0,命令终止。 但是,使用ProcessBuilder : Process p = (new ProcessBuilder(installation_path + uninstall_path + uninstall_command, uninstall_arguments)).start(); p.waitFor(); 退出值是1001,命令终止在中间,虽然waitFor返回。 我该怎么办才能解决ProcessBuilder的问题?

在Java中运行命令行

有没有办法在Java应用程序中运行这个命令行? java -jar map.jar time.rel test.txt debug 我可以用命令运行它,但是我不能在Java中执行它。

如何使pipe道与Runtime.exec()?

考虑下面的代码: String commandf = "ls /etc | grep release"; try { // Execute the command and wait for it to complete Process child = Runtime.getRuntime().exec(commandf); child.waitFor(); // Print the first 16 bytes of its output InputStream i = child.getInputStream(); byte[] b = new byte[16]; i.read(b, 0, b.length); System.out.println(new String(b)); } catch (IOException e) { e.printStackTrace(); […]