Re: [wxlua-users] Can't read output with wxPROCESS_REDIRECT and wxEXEC_ASYNC

2012-10-05 Thread Paul K
Hi João,

Thanks again for your example, as I ended up with something that was
closer to yours than to my original plan (as mine was blocking the app
if the other application wasn't printing anything). For those who are
following the thread, this is what I ended up with:

local proc = wx.wxProcess()
proc:Redirect()
proc:Connect(wx.wxEVT_END_PROCESS, function(event) proc = nil end)
local bid = wx.wxExecute(cmd, wx.wxEXEC_ASYNC +
wx.wxEXEC_MAKE_GROUP_LEADER, proc)
if not bid or bid == -1 or bid == 0 then
  DisplayOutput((Program unable to run as '%s'\n):format(cmd))
  return
end

local streamin = proc:GetInputStream()
for _ = 1, 10 do
  if streamin:CanRead() then
-- do something with streamin:Read(4096)
  end
  wx.wxSafeYield()
  wx.wxWakeUpIdle()
  wx.wxMilliSleep(250)
end

-- kill process if couldn't read after 10 attempts
-- wx.wxProcess.Kill(bid, wx.wxSIGKILL, wx.wxKILL_CHILDREN)

Paul.

On Mon, Oct 1, 2012 at 4:03 AM, João Mendes lord@gmail.com wrote:
 Hi Paul,

 Did you try this:

 proc = wx.wxProcess()

 proc:Connect(wx.wxEVT_END_PROCESS,
   function(event)
   print(Hello - the process is over and won't be deleted.)
   -- event:Skip(true) -- will crash since wxWidgets will delete it
 too
   -- proc = nil
   -- collectgarbage( collect ) -- not necessary, but it tests the
 problem
   end
 )

 proc:Redirect()
 wx.wxExecute( cmd, wx.wxEXEC_ASYNC, proc )

 I get this code somewhere and work fine for me.

 --
 João Mendes de Oliveira Neto


 2012/9/30 Paul K paulclin...@yahoo.com

 Hi All,

 I'm trying to read output from a program and am having trouble with
 the following three lines of code:

   local proc = wx.wxProcess(wx.NULL, wx.wxPROCESS_REDIRECT)
   local pid = wx.wxExecute(cmd, wx.wxEXEC_ASYNC, proc)
   local streamin = proc:GetInputStream()

 The app crashes on any attempt to get input stream. The following code
 with EXEC_SYNC works fine though:

   local pid = wx.wxExecute(cmd, wx.wxEXEC_SYNC)

 But this doesn't give me any way to access the output of the command I
 execute.

 I suspect the problem is in the first parameter in wxProcess:
 wx.wxProcess(wx.NULL, but I don't see any other way to not provide
 wxEvtHandler or create a dummy one (replacing wx.NULL with
 wx.wxEvtHandler() has the same effect: the app crashes).

 This is all on windows 7 running fairly recent 2.8.12.2 code. I'd
 appreciate any ideas on how to get program output. Thanks.

 Paul.


 --
 Got visibility?
 Most devs has no idea what their production app looks like.
 Find out how fast your code is with AppDynamics Lite.
 http://ad.doubleclick.net/clk;262219671;13503038;y?
 http://info.appdynamics.com/FreeJavaPerformanceDownload.html
 ___
 wxlua-users mailing list
 wxlua-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wxlua-users



 --
 Got visibility?
 Most devs has no idea what their production app looks like.
 Find out how fast your code is with AppDynamics Lite.
 http://ad.doubleclick.net/clk;262219671;13503038;y?
 http://info.appdynamics.com/FreeJavaPerformanceDownload.html
 ___
 wxlua-users mailing list
 wxlua-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wxlua-users


--
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
___
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users


Re: [wxlua-users] Can't read output with wxPROCESS_REDIRECT and wxEXEC_ASYNC

2012-10-05 Thread John Labenski
On Fri, Oct 5, 2012 at 1:10 PM, Paul K paulclin...@yahoo.com wrote:
 Hi João,

 Thanks again for your example, as I ended up with something that was
 closer to yours than to my original plan (as mine was blocking the app
 if the other application wasn't printing anything). For those who are
 following the thread, this is what I ended up with:

 local proc = wx.wxProcess()
 proc:Redirect()
 proc:Connect(wx.wxEVT_END_PROCESS, function(event) proc = nil end)
 local bid = wx.wxExecute(cmd, wx.wxEXEC_ASYNC +
 wx.wxEXEC_MAKE_GROUP_LEADER, proc)
 if not bid or bid == -1 or bid == 0 then
   DisplayOutput((Program unable to run as '%s'\n):format(cmd))
   return
 end

 local streamin = proc:GetInputStream()
 for _ = 1, 10 do
   if streamin:CanRead() then
 -- do something with streamin:Read(4096)
   end
   wx.wxSafeYield()
   wx.wxWakeUpIdle()
   wx.wxMilliSleep(250)
 end

The wxWidgets exec sample uses a wxTimer to poll the stream for data.
You just have to connect to wxEVT_END_PROCESS and turn off the timer
when it exits or kill it like you do if it doesn't respond in a timely
fashion.

See, MyFrame::OnExecWithRedirect() and MyFrame::AddPipedProcess()
http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/samples/exec/exec.cpp?view=markup

Regards,
John

ps. My previous comment was to confirm that you have seen the docs and
are doing all the checks. My experience with processes is that they
can be finicky if things aren't just right. In fact, you should always
connect to wxEVT_END_PROCESS in case the user or OS kills your process
for you...

--
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
___
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users