如何使用commons-exec执行/bin/sh? [英] How to execute /bin/sh with commons-exec?
本文介绍了如何使用commons-exec执行/bin/sh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我在做什么:
import org.apache.commons.exec.*;
String cmd = "/bin/sh -c \"echo test\"";
new DefaultExecutor().execute(CommandLine.parse(cmd));
这是输出:
/bin/sh: echo test: command not found
我在做什么错了?
推荐答案
这个对我有用:-
CommandLine command = new CommandLine("/bin/sh");
command.addArguments(new String[] {
"-c",
"echo 'test'"
},false);
new DefaultExecutor().execute(command);
这篇关于如何使用commons-exec执行/bin/sh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文