11
コマンドライン引数をとる実行ファイルを実行するには、Luaでio.popen
を使用する必要があります。 期待される出力をキャプチャできるように、プロセスがLuaで終了するのを待つ方法はありますか? io.popen - プロセスがLuaで終了するのを待つ方法は?
local command = "C:\Program Files\XYZ.exe /all"
hOutput = io.popen(command)
print(string.format(""%s", hOutput))
は、実行可能ファイルは、コマンドライン引数
/all
で呼び出される必要があるXYZ.exeであると仮定します。
io.popen(command)
が実行されると、プロセスは印刷する必要のある文字列を返します。
マイコードスニペット:
function capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
-- wait(10000);
local s = assert(f:read('*a'))
Print(string.format("String: %s",s))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
local command = capture("C:\Tester.exe /all")
あなたの助けが理解されるであろう。
私は何とかそれが適切に – Chet
機能キャプチャ(CMD、生) ローカルF =アサート(io.popen(CMD、R '')) が動作していないコードが生じています - (10000)を待ちます。 ローカルの場合= assert(f:read( '* a')) f:close()raw (s、 '%s + $'、 '') s = string.gsub(s、 '[\ n \ r] +' 、 '') 返信s end ローカルコマンド=キャプチャ( "C:\ Tester.exe/all") – Chet