Java - ProcessBuilder command arguments with spaces and double-quotes fails

前端 未结 1 388
自闭症患者
自闭症患者 2020-12-18 12:55

I\'m using ProcessBuilder to run a Windows executable...the exact command I need to run is :

\"C:\\Program Files\\CCBU\\CCBU.exe\" -d\"C:\\My Data\\projects         


        
相关标签:
1条回答
  • 2020-12-18 13:33

    Add individual strings without "double" quotes..

                    commands.add ( "C:\\Program Files\\CCBU\\CCBU.exe"                      );
                    commands.add ( "-d");
                    commands.add ("C:\\My Data\\projects\\ccbu\\ciccb-report.xls"        );
                    commands.add ( "-tf");
                    commands.add("C:\\Program Files\\CCBU\\loss-billing-filters.txt"   );
                    commandExecutor = new SystemCommandExecutor(commands);
    

    ProcessBuilder will take care of necessary handling of args.


    Pull up comment:

    Jayan, You're idea got me thinking : The following worked :

     commands.add ( "-dC:\\My Data\\projects\\ccbu\\ciccb-report.xls" );
     commands.add ( "-tfC:\\Program Files\\CCBU\\loss-billing-filters.txt"
    

    ); – lincolnadym

    0 讨论(0)
提交回复
热议问题