Get subprocess id in Java

前端 未结 5 911
悲&欢浪女
悲&欢浪女 2020-12-06 05:55

I\'m creating subprocesses in this way:

String command = new String(\"some_program\");

Process p = Runtime.getRuntime().exec(command);

How

5条回答
  •  忘掉有多难
    2020-12-06 06:18

    From here

    public static void main(String[] args) throws IOException {
        byte[] bo = new byte[100];
        String[] cmd = {"bash", "-c", "echo $PPID"};
        Process p = Runtime.getRuntime().exec(cmd);
        p.getInputStream().read(bo);
        System.out.println(new String(bo));
    }
    

提交回复
热议问题