How to execute /bin/sh with commons-exec?
问题 This is what I'm doing: import org.apache.commons.exec.*; String cmd = "/bin/sh -c \"echo test\""; new DefaultExecutor().execute(CommandLine.parse(cmd)); This is the output: /bin/sh: echo test: command not found What am I doing wrong? 回答1: This one works for me:- CommandLine command = new CommandLine("/bin/sh"); command.addArguments(new String[] { "-c", "echo 'test'" },false); new DefaultExecutor().execute(command); 回答2: According to the FAQ "It is recommended to use CommandLine.addArgument()