News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
real time activity
Author Message
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #1
real time activity

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
output_window:show();
while true do
local data = fh:read( "*l" );
if data == nil then break end
br_output:add( data );
output_window:redraw();
br_output:redraw();
end
fh:close();
end
end

Thanks,
-Craig

01-19-2010 03:26 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: real time activity

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.

01-19-2010 04:28 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #3
RE: real time activity

Hi,

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

Take a look at :

examples\3_Examples\luasys\test_pid.lua

That effectively does exactly the same thing.

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

Cheers
JohnM

01-20-2010 07:35 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #4
RE: real time activity

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 192.168.1.1' for the args so it didn't block forever but didn't find a combination that it liked..

Am I trying this correctly?

01-22-2010 04:12 AM
Find all posts by this user Quote this message in a reply
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #5
RE: real time activity

I tried to bury the command a bit... '/bin/ping -c 4 192.168.1.1 | {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....

01-22-2010 05:05 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: