Could you take a look and let me know if you see any glaring issues.
This is iffy: or die "$+, $^E";.
You probably mean $! not $+, and $^E probably won't give you anything unless you are running under windows (or maybe OS/2?).
And you are testing if the thread is joinable, but never joining (or detaching) it. Which means it will hang around until the program ends. At which point you would probably get a warning message.
Also I assumed the way I have it coded would enable me to get whatever was "printed" prior to killing the thread but this does not seem to be the case, any ideas on what I am doing wrong?
I'm not really sure I understand what you mean by that? Exactly where in your code do you want to access it?
You should certainly be able to access the contents of the shared array @result from outside the thread whilst the command is still running. But probably not the way you have it coded currently:
@results = <$fh>;
Perl probably locks the entire array until that statement completes, which won't be until the command completes. If you changed that to push @results, $_ while <$fh>; you might have more success, but remember that you would have to employ locking to prevent conflicts.
Perhaps a better way would be to use a Thread::Queue which is basically just a shared array and a couple of simple methods (or was until they f***ed with it recently!), but it does take care of the locking for you which is a great convenience, as you know it is done right.
However, since timedCommand() can't return anything until you've cleaned up the process and thread, it is hard to see what benefit you would get from that?
In reply to Re^3: How to deal with a forked proces that is waiting for user input?
by BrowserUk
in thread How to deal with a forked proces that is waiting for user input?
by gepapa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |