Hi all, I am using wxLua 2.8.12 for Windows. In the following code,
I try to asynchronously execute some command and redirect its output.
The problem is, if I close main window before child process terminates,
the child process is not deleted. I could still see "tree.com" process
inside Windows Task Manager after this wxLua app exits.
What is the problem with my code below?
--------------------------------------------------------------------
require("wx")
frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "Test")
function ExecCommand(cmd)
proc = wx.wxProcess(frame)
proc:Redirect()
pid = wx.wxExecute(cmd, wx.wxEXEC_ASYNC, proc)
if pid > 0 then
print("process id is " .. tostring(pid))
streamIn = proc and proc:GetInputStream()
end
end
function ReadStream()
if streamIn and streamIn:CanRead() then
local str = streamIn:Read(4096)
end
end
frame:Connect(wx.wxEVT_IDLE, ReadStream)
frame:Connect(wx.wxEVT_END_PROCESS, function(event)
proc = nil
end)
frame:Connect(wx.wxEVT_CLOSE_WINDOW, function(event)
if proc then proc:Detach() end
event:Skip()
end)
frame:Show(true)
cmd = "tree.com C:\\Windows"
ExecCommand(cmd)
wx.wxGetApp():MainLoop()
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users