ProcessBuilder adds extra quotes to command line

前端 未结 3 1800
执笔经年
执笔经年 2020-12-07 01:00

I need to build the following command using ProcessBuilder:

\"C:\\Program Files\\USBDeview\\USBDeview.exe\" /enable          


        
3条回答
  •  执笔经年
    2020-12-07 01:37

    First, you need to split up the arguments yourself - ProcessBuilder doesn't do that for you - and second you don't need to put escaped quotes around the argument values.

    ArrayList test = new ArrayList();
    test.add("C:\\Program Files\\USBDeview\\USBDeview.exe");
    test.add("/enable");
    test.add("My USB Device");
    

    The quotes are necessary on the command line in order to tell the cmd parser how to break up the words into arguments, but ProcessBuilder doesn't need them because it's already been given the arguments pre-split.

提交回复
热议问题