From: Mark D. <mar...@zn...> - 2007-03-26 01:34:57
|
Hi, I wanted to execute an external command and have the output returned to me line by line as events. This would mean I could have long running external process running in the background that periodically reports status to the GUI. It also gives me a simple alternative to threads / POE etc. for certain cases. I've put it together at http://www.wxperl.co.uk/processstream.html A source tar.gz and MSWin32 PPM are downloadable. Both contain an example prog - example/psexample.pl. Just enter a command in the TextCtrl and execute it. It seems to handle multiple concurrent running procs fine. I'd appreciate any comments and views on code, process and namespace. (and if I have wasted my time - has this been done elsewhere?) Regards Mark |
From: Mark D. <mar...@zn...> - 2007-03-27 04:03:21
|
Hi, Following some feedback I have re-implemented the interface and added a number of make tests. Tests complete OK on MSWin32 / Linux, both with Wx-0.70 + wxWidgets 2.8.3 available at http://www.wxperl.co.uk/processstream.html I'd appreciate any comments and views on code, process and namespace. Regards Mark > Hi, > > I wanted to execute an external command and have the output returned to me line by line as events. This would mean I could have long running external process running in the background that periodically reports status to the GUI. It also gives me a simple alternative to threads / POE etc. for certain cases. > > I've put it together at http://www.wxperl.co.uk/processstream.html > > A source tar.gz and MSWin32 PPM are downloadable. Both contain an example prog - example/psexample.pl. Just enter a command in the TextCtrl and execute it. It seems to handle multiple concurrent running procs fine. > > I'd appreciate any comments and views on code, process and namespace. (and if I have wasted my time - has this been done elsewhere?) > > Regards > > Mark > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Eric W. <scr...@gm...> - 2007-03-27 04:58:43
|
# from Mark Dootson # on Monday 26 March 2007 09:03 pm: >I'd appreciate any comments and views on code, process and namespace. I would really like to see some sort of list-context (\@command or otherwise) functionality. I've only briefly looked at the source, so there might be some underlying implementation nit forcing your hand here. my $process = Wx::Perl::ProcessStream->OpenProcess( $command, $name, $eventhandler); With a quick glance around, it seems that Wx.pm supports the "wxExecute(char **argv,..." form via ExecuteArgs(). It also looks like this would be no different than using ExecuteCommand() in terms of firing the callback. Perhaps detecting whether $command is an array ref would do it? Of course, I'm assuming here that the list form in ExecuteArgs() carries all of the not-running-a-shell benefits of `exec(@list)` (such as "no need to escape spaces in filenames" to name one very common example.) If I'm wrong, ugh. See also: execvp(3). The wx docs aren't exactly clear on what happens so ... at least the unix implementation ("src/unix/utilsunx.cpp") reads as if they've reinvented shell escaping. Neat. So, maybe the semicolon ends up as an argument (I think perl goes out of its way to fire-up a shell.) Ooh. The windows implementation puts everything together and calls the string form due to the nature of CreateProcess. Yay. Well, I see from win32/win32.c create_command_line() that perl works a little harder. In any case, I typically build command and arguments as lists. Would rather not have to do join(" ", map({escape($_)} @list)) and then have wx go through that and split on spaces when the operating system is otherwise quite capable of executing a list of "command and arguments". I guess just leave "what should we do when the operating system is not so capable?" as an exercise for the reader. --Eric -- "Everything should be made as simple as possible, but no simpler." --Albert Einstein --------------------------------------------------- http://scratchcomputing.com --------------------------------------------------- |
From: Mark D. <mar...@zn...> - 2007-03-27 05:31:44
|
Hi Eric, Thanks for the pointer to ExecuteArgs; Wx::Perl::ProcessStream->OpenProcess() now accepts an array ref or a command string as the first argument. The array form is implemented simply as a call to Wx::ExecuteArgs; Added a test and uploaded a new version. Regards Mark Eric Wilhelm wrote: > # from Mark Dootson > # on Monday 26 March 2007 09:03 pm: > >> I'd appreciate any comments and views on code, process and namespace. > > I would really like to see some sort of list-context (\@command or > otherwise) functionality. I've only briefly looked at the source, so > there might be some underlying implementation nit forcing your hand > here. > > my $process = Wx::Perl::ProcessStream->OpenProcess( > $command, $name, $eventhandler); > > With a quick glance around, it seems that Wx.pm supports the > "wxExecute(char **argv,..." form via ExecuteArgs(). It also looks like > this would be no different than using ExecuteCommand() in terms of > firing the callback. Perhaps detecting whether $command is an array > ref would do it? > > Of course, I'm assuming here that the list form in ExecuteArgs() carries > all of the not-running-a-shell benefits of `exec(@list)` (such as "no > need to escape spaces in filenames" to name one very common example.) > If I'm wrong, ugh. See also: execvp(3). The wx docs aren't exactly > clear on what happens so ... at least the unix implementation > ("src/unix/utilsunx.cpp") reads as if they've reinvented shell > escaping. Neat. So, maybe the semicolon ends up as an argument (I > think perl goes out of its way to fire-up a shell.) Ooh. The windows > implementation puts everything together and calls the string form due > to the nature of CreateProcess. Yay. Well, I see from win32/win32.c > create_command_line() that perl works a little harder. > > In any case, I typically build command and arguments as lists. Would > rather not have to do join(" ", map({escape($_)} @list)) and then have > wx go through that and split on spaces when the operating system is > otherwise quite capable of executing a list of "command and arguments". > I guess just leave "what should we do when the operating system is not > so capable?" as an exercise for the reader. > > --Eric |
From: Mark D. <mar...@zn...> - 2007-04-01 14:58:42
|
Indeed! Could you let me know what perl -e"use Wx; print Wx::wxVERSION . qq(\n);" gives. It will save me compiling a 2.6.3 version to figure out why my version checking is wrong. By the way, the test is at line 338 of ProcessStream.pm so you could comment out to continue until I sort out the version problem. Johan Vromans wrote: > Hi Mark, > > Can you explain this message from Wx::Perl::ProcessStream: > > Fatal Error: Wx 0.69 compiled with wxWidgets 2.6.3. > Minimum wxWidgets version 2.6.3 required for Wx::Perl::ProcessStream > 0.08 at ... > > I'd say that 2.6.3 satisfies the criterium. > > -- Johan > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Mark D. <mar...@zn...> - 2007-04-01 15:30:22
|
Hi, Schoolboy error with floating point numbers I need if( Wx::wxVERSION() lt '2.006003') { rather than if( Wx::wxVERSION() < 2.006003) { Version 0.09 coming soon. Many thanks. Mark Mark Dootson wrote: > Indeed! > > Could you let me know what > > perl -e"use Wx; print Wx::wxVERSION . qq(\n);" > > gives. > It will save me compiling a 2.6.3 version to figure out why my version checking is wrong. > > By the way, the test is at line 338 of ProcessStream.pm so you could comment out to continue until I sort out the version problem. > > Johan Vromans wrote: >> Hi Mark, >> >> Can you explain this message from Wx::Perl::ProcessStream: >> >> Fatal Error: Wx 0.69 compiled with wxWidgets 2.6.3. >> Minimum wxWidgets version 2.6.3 required for Wx::Perl::ProcessStream >> 0.08 at ... >> >> I'd say that 2.6.3 satisfies the criterium. >> >> -- Johan >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share your >> opinions on IT & business topics through brief surveys-and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> wxperl-users mailing list >> wxp...@li... >> https://lists.sourceforge.net/lists/listinfo/wxperl-users > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Johan V. <jvr...@sq...> - 2007-03-30 14:21:12
|
Mark Dootson <mar...@zn...> writes: > Tests complete OK on MSWin32 / Linux, both with Wx-0.70 + wxWidgets 2.8.3 > available at http://www.wxperl.co.uk/processstream.html > I'd appreciate any comments and views on code, process and namespace. As far as I can test, it does exactly what it is supposed to do! The only problem I had (and that took me hours of debugging) was why the slave process wouldn't read the data that was written to it using WriteProcess. Well, the slave used <STDIN>, and it was just patiently waiting for the newline before making any input available. I was slighty misled by the documentation: $process->WriteProcess('a message to stdin'); Which I'd suggest to change to: $process->WriteProcess("a message to stdin\n"); as a reminder that newlines are important. When playing Q & A with a slave program I noticed that the response is not snappy. Apparently there's a 1-second poll interval hidden somewhere. It would be nice it this could be reduced to 200ms or something similar. (But it could be hidden deeply in Wx -- didn't investigate). For me, this module is exactly what I've needed for a long time! Thanks, Johan |
From: Mark D. <mar...@zn...> - 2007-03-30 21:27:40
|
Johan, Thank you very much for the feedback. I shall update the documents so that it is clear your own code must add line endings. I might also have two methods: Write WriteLine On the timer, there is a default 500 millisecond delay on polling. The code that reads input will keep reading line by line and raise an event for each line until the buffer is empty, and then timeout for 500ms. It operates this way so that if you are running multiple processes you get a line from each in turn rather than any single process 'blocking' reads from everything else. Writes are serialized with the reads so the net effect of a write / read response is 500 * 2 which is exactly the 1 second you have observed. The 'timer' used for polling is the Wx::Timer which claims between 1 second and 1 millisecond accuracy depending on the OS and, no doubt, a multitude of other factors. The same polling timer is shared between all external processes that are running. The timer only runs when you actually have external processes running. I shall add a PollingInterval method so that the timing can be set to whatever is suitable. I'll leave 500ms as the default. Many thanks for the feedback - I'm pleased that it worked for you. Best Regards Mark Johan Vromans wrote: > Mark Dootson <mar...@zn...> writes: > >> Tests complete OK on MSWin32 / Linux, both with Wx-0.70 + wxWidgets 2.8.3 >> available at http://www.wxperl.co.uk/processstream.html >> I'd appreciate any comments and views on code, process and namespace. > > As far as I can test, it does exactly what it is supposed to do! > > The only problem I had (and that took me hours of debugging) was why > the slave process wouldn't read the data that was written to it using > WriteProcess. > > Well, the slave used <STDIN>, and it was just patiently waiting for > the newline before making any input available. I was slighty misled by > the documentation: > > $process->WriteProcess('a message to stdin'); > > Which I'd suggest to change to: > > $process->WriteProcess("a message to stdin\n"); > > as a reminder that newlines are important. > > When playing Q & A with a slave program I noticed that the response is > not snappy. Apparently there's a 1-second poll interval hidden > somewhere. It would be nice it this could be reduced to 200ms or > something similar. (But it could be hidden deeply in Wx -- didn't > investigate). > > For me, this module is exactly what I've needed for a long time! > > Thanks, > Johan > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |
From: Johan V. <jvr...@sq...> - 2007-04-01 14:48:43
|
Hi Mark, Can you explain this message from Wx::Perl::ProcessStream: Fatal Error: Wx 0.69 compiled with wxWidgets 2.6.3. Minimum wxWidgets version 2.6.3 required for Wx::Perl::ProcessStream 0.08 at ... I'd say that 2.6.3 satisfies the criterium. -- Johan |