[wxlua-users] Could not read redirected output for some commands

2015-10-14 Thread Z.H.
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


Re: [wxlua-users] Could not read redirected output for some commands

2015-10-14 Thread Paul K
> 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.

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