Completed demo.
This commit is contained in:
parent
a931f0d748
commit
ee947fc0de
1 changed files with 20 additions and 4 deletions
|
@ -48,7 +48,7 @@ public class CmdExecDemo
|
|||
{
|
||||
//
|
||||
BasicConfigurator.configure();
|
||||
org.apache.log4j.Logger.getRootLogger().setLevel(Level.ERROR);
|
||||
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
|
||||
Logger logger = LoggerFactory.getLogger(CmdExecDemo.class);
|
||||
|
||||
//
|
||||
|
@ -63,7 +63,9 @@ public class CmdExecDemo
|
|||
|
||||
System.out.println("Launch…");
|
||||
|
||||
String result = CmdExecUtils.run("/bin/bash", "-c", "echo '10\n5\n7\n1' > " + tmpFile.getAbsolutePath());
|
||||
// String result = CmdExecUtils.run("/bin/bash", "-c",
|
||||
// "echo '10\n5\n7\n1' > " + tmpFile.getAbsolutePath());
|
||||
String result = CmdExecUtils.run("/bin/bash -c \"echo '10\n5\n7\n1' > " + tmpFile.getAbsolutePath() + " \"");
|
||||
|
||||
System.out.println("result=[" + result + "]");
|
||||
}
|
||||
|
@ -89,8 +91,22 @@ public class CmdExecDemo
|
|||
|
||||
System.out.println("Launch…");
|
||||
|
||||
// String command = "/bin/sort -r /etc/passwd";
|
||||
String[] command = { "/usr/bin/sort", "-n", "-r", tmpFile.getAbsolutePath() };
|
||||
String[] command = { "/usr/bin/sort", "-n", tmpFile.getAbsolutePath() };
|
||||
|
||||
CmdExec cmdexec = new CmdExec(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
|
||||
System.out.println("command=[" + cmdexec.toString() + "]");
|
||||
System.out.println("exitVal=[" + cmdexec.getExitValue() + "]");
|
||||
System.out.println("out=[" + cmdexec.getOutStream() + "]");
|
||||
System.out.println("err=[" + cmdexec.getErrStream() + "]");
|
||||
}
|
||||
|
||||
// #3
|
||||
{
|
||||
System.out.println("========== DEMO #3;");
|
||||
|
||||
System.out.println("Launch…");
|
||||
|
||||
String command = "/usr/bin/sort -n -r " + tmpFile.getAbsolutePath();
|
||||
|
||||
CmdExec cmdexec = new CmdExec(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
|
||||
System.out.println("command=[" + cmdexec.toString() + "]");
|
||||
|
|
Loading…
Reference in a new issue