我尝试了 CommandLine#parse 和 addArgument:
DefaultExecutor executor = new DefaultExecutor();
executor.execute(CommandLine.parse("ls /Users/jizhang/*.py"));
CommandLine cmd = new CommandLine("ls");
cmd.addArgument("/Users/jizhang/*.py", false);
executor.execute(cmd);
例外是:
ls: /Users/jizhang/*.py: No such file or directory
Exception in thread "main" org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
但实际上该文件夹中有文件:
prey:~ jizhang$ ls /Users/jizhang/*.py
/Users/jizhang/ana.py /Users/jizhang/send_image.py
/Users/jizhang/push.py /Users/jizhang/t.py
我相信这是关于报价,但不知道如何解决它。