0
我试图连续运行各种命令与运行时执行。我创建了一个getRuntime方法的实例,并使用同一个实例连续调用不同的命令,但它们都在同一时间执行。如果runtime exec没有被阻塞,那么当第一个命令完成时,执行第二个命令的好方法是什么?runtime exec命令不会连续执行
Runtime runTime = Runtime.getRuntime();
runTime.exec(new String[]{"sh", "-c", "some command"});
runTime.exec(new String[]{"other command"});
runTime.exec(new String[]{"sh","-c","final command"});
你要注意,如果你没有正确的读取输出流,那么你需要注意一些进程chock ... – MadProgrammer
我的回答是正确的替代方法。为什么你投下了票? – gmansoor