How to make pipes work with Runtime.exec()?

后端 未结 4 1525
日久生厌
日久生厌 2020-11-22 03:35

Consider the following code:

String commandf = \"ls /etc | grep release\";

try {

    // Execute the command and wait for it to complete
    Process child =         


        
4条回答
  •  暖寄归人
    2020-11-22 03:57

    @Kaj accepted answer is for linux. This is the equivalent one for Windows:

    String[] cmd = {
    "cmd",
    "/C",
    "dir /B | findstr /R /C:"release""
    };
    Process p = Runtime.getRuntime().exec(cmd);
    

提交回复
热议问题