I've been experimenting with 'shell/pipeline' on windows and post some tests and example results here in case they are of use to others: - basic examples demonstrating windows external commands, - basic examples demonstrating windows internal commands with standard cmd.shell, - basic examples demonstrating windows internal commands with 'new' powershell.cmd shell, - a more complex example showing a command pipeline using powershell commands to do sed-like and grep-like operations.
Cheers, Kieron. **** Examples using Windows external commands: #lang racket/base ; windows-pipeline-1.rkt - basic windows commands with output to stdout and stderr (require shell/pipeline) ; run racket, do arithmetic (run-pipeline '(racket -e "(+ 41 1)") ) ; run java, get java version (run-pipeline '(java -version) ) ; run where, find location of windows where.exe on path (run-pipeline '(where where) ) ; run where, find location of windows cmd.exe on path (run-pipeline '(where cmd) ) Example execution from Windows command prompt: C:\home\racket\shell>racket windows-pipeline-1.rkt > windows-pipeline-1.rkt.out 2>&1 C:\home\racket\shell>type windows-pipeline-1.rkt.out 42 java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) C:\Windows\System32\where.exe C:\Windows\System32\cmd.exe 0 0 0 0 Examples using Windows internal commands, i.e. commands built-in to the cmd.exe shell: #lang racket/base ; windows-pipeline-2.rkt - basic windows internal (cmd.exe) commands with output to stdout and stderr (require shell/pipeline) ; note: run cmd.exe with /c switch to terminate cmd.exe after executing the given command, i.e. terminate without needing to execute the 'exit' command ; run windows cmd.exe shell, run internal 'dir' command to get directory listing of the root of C: drive (run-pipeline '(cmd /c dir C:\\) ) ; run windows cmd.exe shell, run internal 'set' command to the get a complete listing of the environment variables and their values (run-pipeline '(cmd /c set) ) ; run windows cmd.exe shell, run internal 'echo' command to send arguments to standard out (run-pipeline '(cmd /c echo hello world) ) ; run windows cmd.exe shell, run internal 'path' command to get the value of the PATH environment variable (run-pipeline '(cmd /c path) ) ; run windows cmd.exe shell, run internal 'echo' command to get the value of the PATH environment variable (run-pipeline '(cmd /c echo %PATH%) ) Example execution from Windows command prompt: C:\home\racket\shell>racket windows-pipeline-2.rkt > windows-pipeline-2.rkt.out 2>&1 C:\home\racket\shell>type windows-pipeline-2.rkt.out Volume in drive C is Windows Volume Serial Number is 4A0E-59A3 Directory of C:\ 05/06/2016 10:53 PM <DIR> Analytics 07/06/2015 09:57 AM <DIR> Brother 09/14/2015 07:49 AM <DIR> cygwin64 01/08/2016 05:00 PM <DIR> data 11/04/2015 02:18 PM 321,531 DUMP38fa.tmp 09/20/2016 02:51 PM <DIR> home 12/22/2014 07:04 PM <DIR> Intel 07/02/2015 01:19 PM <DIR> OSGeo4W64 07/13/2009 09:20 PM <DIR> PerfLogs 08/28/2016 08:48 PM <DIR> Program Files 09/20/2016 09:21 AM <DIR> Program Files (x86) 09/09/2015 05:50 PM <DIR> Python27 11/12/2015 01:16 PM <DIR> Python27_64 08/29/2016 02:47 PM <DIR> SWSETUP 09/20/2016 09:02 AM <DIR> tools 06/19/2015 02:41 PM <DIR> Users 08/02/2015 02:12 PM <DIR> wamp 09/14/2016 11:48 AM <DIR> Windows 09/07/2016 07:35 PM 42 windows-version.txt 2 File(s) 321,573 bytes 17 Dir(s) 366,015,729,664 bytes free ALLUSERSPROFILE=C:\ProgramData APPDATA=C:\Users\Kieron\AppData\Roaming asl.log=Destination=file CLASSPATH=.;C:\tools\apple\QuickTime\QTSystem\QTJava.zip CommonProgramFiles=C:\Program Files (x86)\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files COMPUTERNAME=NIETZSCHE ... hello world PATH=C:\ProgramData\Oracle\Java\javapath;C:\tools\racket\racket32_6.5\Racket;C:\Program Files (x86)\... C:\ProgramData\Oracle\Java\javapath;C:\tools\racket\racket32_6.5\Racket;C:\Program Files (x86)\... 0 0 0 0 0 Examples using Windows powershell shell: #lang racket/base ; windows-pipeline-3.rkt - basic windows internal (powershell.exe) commands with output to stdout and stderr (require shell/pipeline) ; note: run powershell.exe with /Command switch to terminate powershell.exe after executing the given command, i.e. terminate without needing to execute the 'exit' command ; run windows external command 'where.exe', find location of windows powershell.exe on path (run-pipeline '(where powershell) ) ; run windows powershell.exe shell, run internal 'echo' command to get the value of the arguments to standard out (run-pipeline '(powershell /Command "& {echo Hello World}") ) ; run windows powershell.exe shell, run internal 'write-output' command (run-pipeline '(powershell /Command "& {write-output "test output"}") ) ; run windows powershell.exe shell, run internal 'write-output' command to get the list of running processes - similar to unix 'ps' (run-pipeline '(powershell /Command "& {$p = get-process; write-output $p;}") ) Example execution from Windows command prompt: C:\home\racket\shell>racket windows-pipeline-3.rkt > windows-pipeline-3.rkt.out 2>&1 C:\home\racket\shell>type windows-pipeline-3.rkt.out C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Hello World test output Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 78 9 2800 3052 86 2.57 1076 AccelerometerSt 163 10 7324 8220 574 0.50 1200 bash 192 23 42140 48632 228 525.05 3184 chrome 181 22 35228 27380 216 2.20 3944 chrome 168 9 1496 3276 66 0.12 4608 chrome 187 22 36600 28572 214 1.37 5304 chrome 267 27 35896 30700 306 1.72 5708 chrome 284 30 62344 56520 334 103.52 5740 chrome 1508 101 69124 86340 408 136.67 2768 explorer 1156 110 335276 389796 936 1,722.89 2124 firefox 0 0 0 24 0 0 Idle 384 27 8976 11068 91 1940 spoolsv 797 35 31096 23580 135 580 svchost 80 10 1672 2524 48 668 wininit 118 9 3196 5396 57 960 winlogon ... 0 0 0 0 Examples using Windows command pipelines that include the powershell shell to mimic some basic *nix utilities: #lang racket/base ; windows-pipeline-4.rkt - examples of command pipelines that include powershell.exe commands (require shell/pipeline) ; note: run cmd.exe with /C switch to terminate cmd.exe after executing the given command, i.e. terminate without needing to execute the 'exit' command ; note: run powershell.exe with /Command switch to terminate powershell.exe after executing the given command, i.e. terminate without needing to execute the 'exit' command ; a 3-component chain: ; run windows internal cmd.exe command 'path' to get the contents of the environment variable PATH, send to a powershell to split on ';', send to another powershell to look for the case insensitive string 'system' (run-pipeline '(cmd /c path) '(powershell /Command "$Input -split ';'") '(powershell /Command "$Input | select-string -pattern 'system'") ) ; a 3-component chain: ; run windows internal cmd.exe command 'path' to get the contents of the environment variable PATH, send to a powershell to split on ';', send to another powershell to look for the case sensitive string 'system' (run-pipeline '(cmd /c path) '(powershell /Command "$Input -split ';'") '(powershell /Command "$Input | select-string -pattern 'system' -casesensitive") ) ; for completeness the same command in one powershell step: ; run windows internal powershell.exe command to get the 'path' environment variable, split on ';', select only those with case sensitive string 'system' (run-pipeline '(powershell /Command "$Env:path | %{$_.split(';')} | select-string -pattern 'system' -casesensitive") ) Example execution from Windows command prompt: C:\home\racket\shell>racket windows-pipeline-4.rkt > windows-pipeline-4.rkt.out 2>&1 C:\home\racket\shell>type windows-pipeline-4.rkt.out C:\windows\system32 C:\windows\System32\Wbem C:\windows\System32\WindowsPowerShell\v1.0\ C:\tools\apple\QuickTime\QTSystem\ C:\windows\system32 C:\windows\system32 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.