|Welcome to the Monastery|
threads, file handles and wxPerlby sdetweil (Sexton)
|on Feb 13, 2013 at 16:10 UTC||Need Help??|
sdetweil has asked for the
wisdom of the Perl Monks concerning the following question:
In my wxPerl based application, I need to launch and communicate (both its output and its input, stdin) with a shell scripted application (I also wrote).
in the event handler for the start button, we spin off a thread threads->create(\&routine), and it handles all the work.
uses open3 to start the child process, and reads its output (stdout & err) handles to get the console output and put it in a wxPerl textcontrol in a while(<HIS_OUT>) loop.
all works great.. up to the point the child issues a read
now I need to put up a dialog box to get content from the user and then write the response back to the child process.
per the Wx::Thread doc on CPAN http://search.cpan.org/~mbarbon/Wx-0.9701/lib/Wx/Thread.pod I have setup a EVT_COMMAND event handler.
and when the data is detected in the subthread
to send the event message which causes my handler to fire. all works great. I put up the dialog, get the text from the user..
now I need to write back to the clients stdin ... but it was created in the thread subroutine. like this
and I can write to it successfully in the thread
however, I haven't found any way to get the handle from the thread to the main window loop. seems globs are not shareable.
anyone have any ideas?
when I try to use $panel->ProcessEvent() my application crashes with no feedback as soon as the dialog window is started. unlikely it is a stack size problem as the default is 16MB on Windows
on linux the dialog window appears, but then we crash, regardless of ok or cancel. and this is written to the console /usr/libexec/xxx.pl: No such file or directory.
late breaking update after successfully resolving all my issues, seeking something else wxPerl related, I came across Wx::Perl::ProcessStream, which completely replaces all the threading, open3(), file handle, and inter thread communication issues..
net reduction of complexity..
lines of output from the child process fire subroutines, methods provided to write back..