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()

------------------------------------------------------------------------------
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to