|
|
||
次世代 Windows シェルと言われている PowerShell は対話型シェルの機能を持っていますが、昔ながらの VBScript では実現できないのでしょうか?と、思っていたら、以下のようなサンプルを見つけました。
■ VBScript interactive shell
http://www.kryogenix.org/days/2004/04/01/interactiveVbscript
' File : console.vbs ' Usage : CScript //Nologo console.vbs do while true wscript.stdout.write(">>> ") ln = wscript.stdin.readline if lcase(trim(ln)) = "exit" then exit do on error resume next err.clear execute ln if err.number <> 0 then wscript.echo(err.description) on error goto 0 loop
CScript console.vbs [Enter]
上記のコマンドを実行すると以下のように 対話的に VBScript のコマンドを実行することが可能になります。終了は「exit」です。
>>> strMessage = "Hello" [Enter]
>>> CreateObject("SAPI.SpVoice").Speak strMessage [Enter]
>>> exit [Enter]
基本的に Execute() しているだけですが、対話型シェルっぽく動作してくれます。
ただし、関数を作成しようとすると、エラーになってしまうようです。
>>> Function Hoge() 'End' がありません。
その場合は、関数を1行に収めることで実行が可能なようです。
>>> Function Hoge() : WScript.Echo "Hello" : End Function >>> Call Hoge() Hello
Arya2012/04/08 15:20Good to find an expert who knows what he's tlaikng about!
nqhnabxqyg2012/04/09 23:489FNERq , [url=http://htdsbwveyfev.com/]htdsbwveyfev[/url], [link=http://nxwuulswerst.com/]nxwuulswerst[/link], http://dtbycsdgtahd.com/