I want to execute a command like this in java code,
gzip -c /tmp/specificPreffix_2013-11-06.txt > /tmp/specificPreffix_2013-11-06.txt.gz
My system is RHEL5, and I have granted the file access permission.
It doesn't work when I use the open source org.apache.commons.exec.DefaultExecutor. Could anyone help to point out why this happened, or let me know if there is another way. Thanks in advance.
You may get my usage as below:
CommandLine cmd = new CommandLine("gzip").addArgument("-c").addArgument("/tmp/specificPreffix_2013-11-06.txt").addArgument(">").addArgument("/tmp/specificPreffix_2013-11-06.txt.gz");
OutputStream outputStream = new ByteArrayOutputStream();
DefaultExecutor exec = new DefaultExecutor();
exec.setWatchdog(new ExecuteWatchdog(timeoutInMilliSeconds));
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
exec.setStreamHandler(streamHandler);
exec.execute(cmd);
>. Try runningbashthrough the executor, with-cas the first argument, and the entire string that you're trying to run as the second argument.>, the code is like this,CommandLine cmd = new CommandLine("bash").addArgument("-c").addArgument("gzip /tmp/specificPreffix_2013-11-06.txt");, something I did wrong?Runtime.getRuntime().exec( ... )?