From: Z.H. <zo...@ye...> - 2015-10-14 12:52:23
|
I download wxLua-2.8.12.3-Lua-5.2.2-MSW-Unicode.zip and wrote the following code for testing wxExecute function. But the results of "streamin:Read" function are always empty. I have tried the exec example contained in wxWidgets' source code. And I could see the redirected output with this command "cmd /k tree d: & exit". If I replace the command "cmd /k tree d: & exit" with "attrib", I could get the desired result. What's the problem with the following code? ------------------------------------------------- package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;" require("wx") frame = wx.wxFrame( wx.NULL, wx.wxID_ANY,"wxLua Demo", wx.wxDefaultPosition, wx.wxSize(600,480), wx.wxDEFAULT_FRAME_STYLE ) console = wxstc.wxStyledTextCtrl(frame, wx.wxID_ANY) console:Show(true)function Output(message) console:AppendText(message) console:GotoPos(console:GetLength())endlocal proc, streamin function ReadIt(event)if streamin and streamin:CanRead()then Output("Can Read\n")local str = streamin:Read(4096) print(str) Output(str .."\n")else Output("No Output\n")endendlocal myTimer = wx.wxTimer(frame) frame:Connect(wx.wxEVT_TIMER, ReadIt)function Execute() proc = wx.wxProcess() proc:Redirect() proc:Connect(wx.wxEVT_END_PROCESS,function(event) myTimer:Stop(); Output("Process Ended\n") ReadIt() proc =nilend)local cmd ="cmd /k tree d: & exit" Output("Running program: ".. cmd .."\n")local pid = wx.wxExecute(cmd, wx.wxEXEC_ASYNC, proc) Output("Pid is ".. pid .."\n") streamin = proc and proc:GetInputStream() myTimer:Start(500);end frame:Show(true) Execute() wx.wxGetApp():MainLoop() |
From: Paul K <pau...@ya...> - 2015-10-14 15:00:14
|
> I download wxLua-2.8.12.3-Lua-5.2.2-MSW-Unicode.zip and wrote the following code for testing wxExecute function. But the results of "streamin:Read" function are always empty. > local cmd = "cmd /k tree d: & exit" > Output("Running program: " .. cmd .. "\n") I used a slightly different command ("cmd /k dir & exit"), but it worked just fine when I ran it from ZeroBrane Studio. Maybe try with a different wx.dll library? Paul. |
From: Z.H. <zo...@ye...> - 2017-05-19 12:29:35
|
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() |
From: Z.H. <zo...@ye...> - 2015-10-15 01:52:14
|
The command "cmd /k dir & exit" did not work when I ran it from ZBS. At 2015-10-14 22:59:47,"Paul K" <pau...@ya...> wrote: >> I download wxLua-2.8.12.3-Lua-5.2.2-MSW-Unicode.zip and wrote the following code for testing wxExecute function. But the results of "streamin:Read" function are always empty. >> local cmd = "cmd /k tree d: & exit" >> Output("Running program: " .. cmd .. "\n") > >I used a slightly different command ("cmd /k dir & exit"), but it >worked just fine when I ran it from ZeroBrane Studio. Maybe try with a >different wx.dll library? > >Paul. > >------------------------------------------------------------------------------ >_______________________________________________ >wxlua-users mailing list >wxl...@li... >https://lists.sourceforge.net/lists/listinfo/wxlua-users |
From: Paul K <pau...@ya...> - 2015-10-15 02:14:19
|
> The command "cmd /k dir & exit" did not work when I ran it from ZBS. What do you mean by "did not work"? This is what I get for that command: Running program: cmd /k dir & exit Pid is 18556 Can Read Volume in drive D is FILES Volume Serial Number is 6AF1-AFBB ... If I pass the wrong command, I get "Can Read" and then "No Output", which is what you'd expect. Paul. |
From: Z.H. <zo...@ye...> - 2015-10-15 02:39:50
|
What I get for that command is: Running program: cmd /k dir & exit Pid is 6640 Process Ended Can Read And no further result. It's very strange. At 2015-10-15 10:13:53,"Paul K" <pau...@ya...> wrote: >> The command "cmd /k dir & exit" did not work when I ran it from ZBS. > >What do you mean by "did not work"? This is what I get for that command: > >Running program: cmd /k dir & exit >Pid is 18556 >Can Read > Volume in drive D is FILES > Volume Serial Number is 6AF1-AFBB >... > >If I pass the wrong command, I get "Can Read" and then "No Output", >which is what you'd expect. > >Paul. > |
From: Paul K <pau...@ya...> - 2015-10-16 05:11:58
|
> Running program: cmd /k dir & exit > Pid is 6640 > Process Ended > Can Read > And no further result. It's very strange. It is strange. It's as if the program is done, but nothing is "waiting" in the output to be read. Did you say you were running on Win10? Maybe it's a new "feature"? I'd try on some other Windows machine you may have access to... Paul. |
From: Z.H. <zo...@ye...> - 2015-10-16 07:57:24
|
I was running on Windows 7, 32bit. At 2015-10-16 13:11:30,"Paul K" <pau...@ya...> wrote: >> Running program: cmd /k dir & exit >> Pid is 6640 >> Process Ended >> Can Read >> And no further result. It's very strange. > >It is strange. It's as if the program is done, but nothing is >"waiting" in the output to be read. Did you say you were running on >Win10? Maybe it's a new "feature"? > >I'd try on some other Windows machine you may have access to... > >Paul. |