|
テーマ:ソフトウェア開発(53)
カテゴリ:UWSC
uwscのpowershell関数にあれこれ悩んでいます。
まず、起動が遅い。起動するためのオーバーヘッドは半端ないんだろうな。 しかも、起動したpowershellのインスタンスを再利用できません。 前回の結果を次のセッションで利用することができず、いつも単発の呼び出しだけ。 じゃ、uwscからpowershellを呼ぶんじゃなくて、powershellからuwscを呼べばいいんじゃない? あるんですよ。 stuncloud さんのPoshUwsc とか しゅんさんのpowershell_uwsc_bridge とか。 でも、uwscメーンで、powershellのインタンスを1回起動したら、そのあとそのインスタンスとやり取りしたいってのもあってもいいんじゃない。つまり、powershellを起動しっぱなしにする。powershell側に目に見えないGUIを持たせてUWSCから操縦するってのを作ってみました。 uwscユーザーですので、ソケットとかHTTPサーバとかじゃなく、ひたすらgetid sendstr clkitem getstrでいきます。 ※debugをtrueにすればGUIが見えます。 ※以前やったUWSCのpowershell関数をスピードアップの改訂版です。 呼び出し例 StayOnPs.debug=false sop=StayOnPs.new() msgbox(StayOnPs.execute("ls")) msgbox(StayOnPs.execute("ls ..")) stayOnPS.uws module StayOnPs dim instancemax=10 hashtbl instance public DEBUG=true function new() if length(instance)>instancemax msgbox("powershellの実行数が上限を超えました") exit endif uwsPid=status(getid(get_thisuwsc_win),st_process) result=uwsPid + "_" + gettime() result=result + "_" + g_time_zz2 src=replace(psdlg_src,"<TITLE>",result) src=replace(src,"<UWSPID>", uwsPid) if DEBUG src=replace(src,"<DEBUG>", "$true") else src=replace(src,"<DEBUG>", "$false") endif powershell(src,true,false) id=getid(result,,5) if status(id, st_isid) ctrlwin(id,show) instance[result]=1 else msgbox("powershellの実行に失敗") exit endif textblock psdlg_src add-type -assembly system.windows.forms $title="<TITLE>" $uwsPid="<UWSPID>" $doNotShow=!<DEBUG> $prompt="sop>" $timer=new-object windows.forms.timer -property @{interval=55} $form=new-object windows.forms.form -property @{text=$title} $timer.add_tick({ if(ps -id $uwsPid){ }else{ ps -id $pid|kill } }) $form.add_shown({$timer.start()}) $base=new-object windows.forms.flowlayoutpanel -property @{dock="fill";parent=$form} $inBox=new-object windows.forms.textbox -property @{ parent=$base; multiline=$true; text=$prompt } $outLabel=new-object windows.forms.label -property @{ parent=$base; text=$prompt } $clr=new-object windows.forms.button -property @{ parent=$base; text="reset" } $exe=new-object windows.forms.button -property @{ parent=$base; text="exec" } $quit=new-object windows.forms.button -property @{ parent=$base; text="quit"; dialogresult="ok" } $clr.add_click({ $outLabel.text=$prompt $inBox.text=$prompt }) $exe.add_click({ try{ $res=iex $inBox.text }catch{ $res=$error[0] } $outLabel.text=$res $inBox.text=$prompt }) if ($doNotShow){ $form.opacity=0.01 $form.formborderstyle="none" } $form.showdialog() endtextblock fend function quit(title="newest") if title="newest" title=instance[length(instance)-1,hash_key] endif result=clkitem( getid(title), "quit" ) if result endif fend procedure quitAll() for i =0 to length(instance)-1 this.quit( instance[i, hash_key ]) next fend function execute(str,title="newest") if title="newest" title=instance[length(instance)-1,hash_key] endif id=getid(title) clkitem(id,"reset") sendstr(id,str,1,true) clkitem(id,"exec") repeat result=getstr(id,0,str_acc_static) until result<>"sop>" fend endmodule
最終更新日
2019.10.05 21:15:51
コメント(0) | コメントを書く
[UWSC] カテゴリの最新記事
|