satocchiaブログ
2026
2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
1月
2月
3月
4月
5月
6月
7月
8月
9月
10月
11月
12月
全1件 (1件中 1-1件目)
1
UWSCにはpowershell関数が組み込み関数として存在しています。これはこれで便利なんだけど、PS1スクリプトからちょこっと、UWSCのfukidasi関数とか使いたいなってことありますよね。#UWSCを実行する関数#引数がファイルとして存在するならUWSCスクリプトファイルと見なして実行、さもなければ、引数をUWSCプログラム本体と見なして実行する。#戻り値: スクリプトファイルを引数としたとき → uwscのプロセス オブジェクト#戻り値: スクリプト文字列を引数としたとき → 一時UWSCファイルのパス(UWSC終了時には消えるので無意味になる)# # ※実行後即リターンするが、戻り値チェックでUWSC実行中かどうか判別できる# test-path $戻り値 または !$戻り値.HasExitedfunction uwsc( $f_or_s ){ $uwscexe ="uwsc.exeのフルパス" if ( !$f_or_s ){ @" 用例:uwsc uwscプログラム文字列|uwscスクリプトのパス"@|write-host return } #スクリプトファイルの場合 if ( ( test-path -isvalid $f_or_s ) -and ( test-path $f_or_s ) ){ #引数が有効なファイルパス文字列で、かつ、ファイルが存在すればuwsスクリプトとして実行 $arglist=,$f_or_s $arglist+=$args $arglist[0]=(gi $arglist[0]).fullname #相対パスが使えなさそうなので絶対パスにしておく $ps =start-process -Filepath $uwscexe -ArgumentList $arglist -NoNewWindow -PassThru return $ps } #プログラム文字列の場合 do{ $tmp =[System.IO.Path]::GetTempFileName() $tmpuws =$tmp -replace "[.]tmp$", ".uws" if ( test-path $tmpuws ){ rm $tmp continue } mv $tmp $tmpuws|out-null }while(0) $f_or_s|out-file -encoding unicode $tmpuws $result =iex "$uwscexe $tmpuws"# while( !!(gwmi "win32_process"|where{ $_.CommandLine -like "*${uwscexe}*${tmpuws}*" }) ){} start-job -scriptBlock { param( $uwscexe, $tmpuws ) while( !!(gwmi "win32_process"|where{ $_.CommandLine -like "*${uwscexe}*${tmpuws}*" }) ){} rm $tmpuws } -argumentlist @( $uwscexe, $tmpuws ) |out-null return $tmpuws}#実行例#uwsc @"#msgbox( "a" )#"@
2018.01.16
コメント(0)