Murga-Projects Forums
real time activity - Printable Version

+- Murga-Projects Forums (
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: real time activity (/showthread.php?tid=373)

real time activity - ceeuu - 01-19-2010 03:26 AM

Got a question...
I'm trying to gather the output of a system command and display it in a browser object, however, if the command takes a while the window will not appear (with the browser object in it) until the command is complete.. even-though the command is producing output. Actually the output window will start to appear, depending on the command, but won't fully paint. For example doing a ping or traceroute and showing the output as it is produced. Is there a better/recommended way to do this:

function execute_cmd()
local fh = io.popen( cmd );
if ( fh ) then
while true do
local data = fh:read( "*l" );
if data == nil then break end
br_output:add( data );


RE: real time activity - mikshaw - 01-19-2010 04:28 AM

I tried messing with this a couple of times, and didn't find an easy way to do it.

I suspect coroutines are an answer, but I'm afraid I can't help with that.

RE: real time activity - JohnMurga - 01-20-2010 07:35 AM


co-routines might help, but I suspect it'll still block.

Take a look at :


That effectively does exactly the same thing.

Basically instead of calling itself with "murgaLua_ExePath", you'd call your cmd with parameters.


RE: real time activity - ceeuu - 01-22-2010 04:12 AM

To test I used the test_pid.lua file and replaced 'murgaLua_ExePath' with "/bin/ping" and placed the IP address into the first place of 'args'.. but it still blocks. I was trying to do something like '-c 4' for the args so it didn't block forever but didn't find a combination that it liked..

Am I trying this correctly?

RE: real time activity - ceeuu - 01-22-2010 05:05 AM

I tried to bury the command a bit... '/bin/ping -c 4 | {while read line; do echo $line; done }' but couldn't figure out how to get it into the sys.spawn() call.. but did put it into a script and call it with the address as an arg and it does allow the timer to work. The output from the command/script is captured from what looks like a mixture of the fdi:read() call in the on_timer function and the fdi:read() call just beyond the sys.spawn() block,.. removing the one beyond sys.spawn() allows the one in on_timer() to handle all output (need to populate a widget). Now I guess I just need to kill the timer when all the data has been retrieved.. how do I do that?

Oh, and since I moved the command to a script and call it with an arg it doesn't really need the extra while loop layer. I'm wondering if I could place this command into sys.spawn() if I would need the call to an outside script....