0
点赞
收藏
分享

微信扫一扫

Java 执行命令 Apache Common-Exec

command = "cmd.exe /c "+command;
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(stdout);
CommandLine cl = CommandLine.parse(command);
DefaultExecutor exec = new DefaultExecutor();
exec.setStreamHandler(psh);
try{
exec.execute(cl);
}catch (Exception e){
e.printStackTrace();
}
return stdout.toString();

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>

使用Apache Common-Exec 框架


举报

相关推荐

0 条评论