diff --git a/examples/powershell/README.txt b/examples/powershell/README.txt new file mode 100644 index 0000000..29d5791 --- /dev/null +++ b/examples/powershell/README.txt @@ -0,0 +1,7 @@ +This examples directory shows some examples written in PowerShell. + +On Windows, note that each .ps1 file also requires a .cmd file to launch it. +The WebSocket should connect to ws://..../[example].cmd. +On Linux this is not required due to the shebang (#!/usr/bin/env pwsh). + +You can also test the command files by running from the command line. \ No newline at end of file diff --git a/examples/powershell/count.cmd b/examples/powershell/count.cmd new file mode 100644 index 0000000..b23bccd --- /dev/null +++ b/examples/powershell/count.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -NoProfile -ExecutionPolicy Bypass %0\..\count.ps1 diff --git a/examples/powershell/count.ps1 b/examples/powershell/count.ps1 new file mode 100644 index 0000000..9093675 --- /dev/null +++ b/examples/powershell/count.ps1 @@ -0,0 +1,6 @@ +#!/usr/bin/env pwsh + +for ($i = 1 ; $i -le 10; $i++) { + Write-Host $i + Start-Sleep -Milliseconds 500 +} diff --git a/examples/powershell/dump-env.cmd b/examples/powershell/dump-env.cmd new file mode 100644 index 0000000..3e38473 --- /dev/null +++ b/examples/powershell/dump-env.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -NoProfile -ExecutionPolicy Bypass %0\..\dump-env.ps1 diff --git a/examples/powershell/dump-env.ps1 b/examples/powershell/dump-env.ps1 new file mode 100644 index 0000000..a84b9f2 --- /dev/null +++ b/examples/powershell/dump-env.ps1 @@ -0,0 +1,45 @@ +#!/usr/bin/env pwsh + +# Standard CGI(ish) environment variables, as defined in +# http://tools.ietf.org/html/rfc3875 +$varNames = @( + "AUTH_TYPE", + "CONTENT_LENGTH", + "CONTENT_TYPE", + "GATEWAY_INTERFACE", + "PATH_INFO", + "PATH_TRANSLATED", + "QUERY_STRING", + "REMOTE_ADDR", + "REMOTE_HOST", + "REMOTE_IDENT", + "REMOTE_PORT", + "REMOTE_USER", + "REQUEST_METHOD", + "REQUEST_URI", + "SCRIPT_NAME", + "SERVER_NAME", + "SERVER_PORT", + "SERVER_PROTOCOL", + "SERVER_SOFTWARE", + "UNIQUE_ID", + "HTTPS" +) + +$environmentVariables = [Environment]::GetEnvironmentVariables() + +foreach ($key in $varNames) { + $value = $environmentVariables.Item($key) + if ([string]::IsNullOrEmpty($value)) { + $value = "" + } + Write-Host "$key=$value" +} + +# Additional HTTP headers +foreach ($item in $environmentVariables.GetEnumerator()) { + $key, $value = $item.Key, $item.Value + if ($key.StartsWith("HTTP_")) { + Write-Host "$key=$value" + } +} diff --git a/examples/powershell/greeter.cmd b/examples/powershell/greeter.cmd new file mode 100644 index 0000000..60bb1b4 --- /dev/null +++ b/examples/powershell/greeter.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -NoProfile -ExecutionPolicy Bypass %0\..\greeter.ps1 diff --git a/examples/powershell/greeter.ps1 b/examples/powershell/greeter.ps1 new file mode 100644 index 0000000..dd74ed5 --- /dev/null +++ b/examples/powershell/greeter.ps1 @@ -0,0 +1,7 @@ +#!/usr/bin/env pwsh + +# For each line FOO received on STDIN, respond with "Hello FOO!". +while ($true) { + $line = Read-Host + Write-Host "Hello $line!" +}