CommandExecutor executor = new CommandExecutor();
A "dir" command with "System.out" used as dump stream.
executor.exec("dir", System.out);
The output (on the console) is:
Volume in drive C is Windows7_OS Volume Serial Number is 1CD2-4448 Directory of C:\Work\Projects\jatoo-exec 07/28/2014 03:47 PM <DIR> . 07/28/2014 03:47 PM <DIR> .. 07/28/2014 10:17 AM 1,433 .classpath 07/28/2014 10:17 AM 9 .gitignore 07/28/2014 10:17 AM 562 .project 07/28/2014 10:17 AM <DIR> .settings 07/28/2014 03:02 PM 2,186 pom.xml 07/28/2014 12:55 PM <DIR> src 07/28/2014 04:04 PM <DIR> target 4 File(s) 4,190 bytes 5 Dir(s) 270,382,510,080 bytes free
A "dir" command executed in a specific folder (working folder) and with "System.out" used as dump stream.
executor.exec("dir", new File("c:\\Users\\Public\\Pictures\\Sample Pictures"), System.out);
The output (on the console) is:
Volume in drive C is Windows7_OS Volume Serial Number is 1CD2-4448 Directory of c:\Users\Public\Pictures\Sample Pictures 07/28/2014 04:12 PM <DIR> . 07/28/2014 04:12 PM <DIR> .. 07/14/2009 08:32 AM 879,394 Chrysanthemum.jpg 07/14/2009 08:32 AM 845,941 Desert.jpg 07/14/2009 08:32 AM 595,284 Hydrangeas.jpg 07/14/2009 08:32 AM 775,702 Jellyfish.jpg 07/14/2009 08:32 AM 780,831 Koala.jpg 07/14/2009 08:32 AM 561,276 Lighthouse.jpg 07/14/2009 08:32 AM 777,835 Penguins.jpg 07/14/2009 08:32 AM 620,888 Tulips.jpg 9 File(s) 5,837,943 bytes 2 Dir(s) 270,382,235,648 bytes free
A "dir" command executed in a specific folder (working folder) with the output redirected. A dump output stream is not used any more because in this case we know the command will dump everything to a file.
executor.exec("dir >> list.txt", new File("c:\\Users\\Public\\Pictures\\Sample Pictures"));
A file with the output of the command will be created:
c:\Users\Public\Pictures\Sample Pictures\list.txt