How to use javas Process.waitFor()?

后端 未结 3 1006
既然无缘
既然无缘 2021-01-29 03:12

I am trying to run command line commands from Java and a quick sanity check made me realize that the reason I am having trouble is that I can\'t get the pr.waitFor()

3条回答
  •  故里飘歌
    2021-01-29 03:33

    You should try this:

    Process pr = rt.exec(new String[]{ "bash","-c", "sleep 32; echo $RANDOM" });
    

    This launches a shell process and then within the shell runs your commands. The shell doesn't return till AFTER the commands have completed.

    Let me know if that works for you.

提交回复
热议问题