PowerShellで、標準入力をMessageBoxに出すMessageBox.PS1を作る。(その2)
では、$inputを使うとどうでしょう?
MessageBox.PS1
$a=@()
$input|foreach{$a+=$_}
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show([String]::Join("`r`n",$a))
こうすると、(その1)で駄目だった以下が可能になります。
CMD.EXE
powershell.exe
type hoge.txt | .\MessageBox.PS1
※ PowerShellは、< を未サポート。パイプで代替する。
CMD.EXE
powershell.exe
dir | .\MessageBox.PS1
※ PowerShell内のパイプは、[System.Console]::Inで読めない。$inputで読む。
CMD.EXE
powershell.exe -command "$input | .\MessageBox.PS1" < hoge.txt
※ -commandは、PowerShell内のパイプと同じ。$inputで読む。
CMD.EXE
dir | powershell.exe -command "$input | .\MessageBox.PS1"
※ 同じ。
CMD.EXE
dir | PS.CMD MessageBox.PS1
※ 関連付けの問題。ここではPS.CMDを使用。
CMD.EXE
PS.CMD MessageBox.PS1 < hoge.txt
※ 同じ。
ただし、(その1)のシンタクスとの違いに注意。
ここで新出のPS.CMDは後述します。また、関連付けも、後述します。
逆に、(その1)で出来たことが(その2)では出来ません。:-(
« PowerShellで、標準入力をMessageBoxに出すMessageBox.PS1を作る。(その1) | トップページ | PowerShellで、標準入力をMessageBoxに出すMessageBox.PS1を作る。(その3) »