Java exec() does not return expected result of pipes' connected commands

后端 未结 6 543
傲寒
傲寒 2020-12-11 05:58

I\'m calling command line programs connected by pipes. All this works on Linux for sure.

My method:

protected String execCommand(String command) thro         


        
6条回答
  •  囚心锁ツ
    2020-12-11 06:19

    Probably a little too late but for others looking for a solution, try this...

    String[] cmd = {
                            "/bin/sh",
                            "-c",
                            "cat /proc/cpuinfo | wc -l"
                        };
    
    Process process = Runtime.getRuntime().exec(cmd);
    

    All the best..

提交回复
热议问题