Perl v5.8.5 Threads Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl v5.8.5 Threads Problem
# 1  
Old 07-13-2009
Perl v5.8.5 Threads Problem

Hi Unix gurus,
I am facing a threading problem in Perl.
I have a worker thread in perl in which I am calling a shell script.
The shell script echo's output to the Standard Output from time to time as it progresses.

In the worker thread, I am unable to display the echo statement of shell script as and when it is echoed.
However, the thread prints the Standard Output of the shell script when the script ends.

Here is some code to demonstrate what i am trying to do:

Code:
 
@outputs=`shellscript 2>&1`  # This is where the script is called and its retutrned in the variable outputs
foreach my $output ( @outputs )
{
            print "WRKTH#$index = $output";
}

I want how I can print the 'outputs' as and when it is popuated.
Please also provide some sample code.
Please advise.
Thanks.
# 2  
Old 07-13-2009
Your problem is that the backticks will spawn a subprocess which will exec(v) your command, collect the output and only then return. You'll be better of opening a filehandle for the process' output:
Code:
open my $FH, 'shellscript 2>&1 |' or die "Can't open process for reading: $!";
while(my $output=<$FH>)
...

See perldoc -f open for details.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Threads Terminating Abnormally.

I've used threads before, but not with Perl. I tried looking up these errors and using 'join' instead of 'detach' with no luck. Here is the code I am currently using: #!/usr/bin/perl -w use warnings; use threads; use threads::shared; $Linux='Linux'; $Greek='Greek'; my... (3 Replies)
Discussion started by: Azrael
3 Replies

2. Shell Programming and Scripting

using threads in perl

Hi everyone, I am trying to create a script which runs a number of processes simultaneously and at the same time use a timer to keep track of what is going on. The problem is that the timer stops and the script exits upon the completion of some of the processes, whereas I want to timer to... (0 Replies)
Discussion started by: free2rhyme2k
0 Replies

3. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

4. Programming

Problem with timely execution of threads...

Hi Guys, We are having one multi-threaded application. The scenario is as follows: --------------------------------- Client 1 | APP Server -------------- Client 2 ... (1 Reply)
Discussion started by: 14341
1 Replies

5. Shell Programming and Scripting

perl launch threads in an array variable?

Im having a problem launching multiple sub routines as threads. My script seems to stop when the first thread is launched. Im condensing the code for simplification here: #!/usr/bin/perl -w use strict; use threads; srand; my ($cnt,$line,$iprange_rand); my... (2 Replies)
Discussion started by: trey85stang
2 Replies

6. Programming

problem with threads in C

I have problem that if I create for example 100 threads program work correctly but if I define more threads for example 1000 // if I change static int NUM_E from 100 to 1000 than program stop about 350 threads and doesn't continue where should be problem please? #include <pthread.h>... (4 Replies)
Discussion started by: Sevco777
4 Replies

7. HP-UX

%Internal DCE Threads problem (version CMA BL10+)

Hi, I have a module by the name gateway, and it core dumps and gives a cma_dump.log file which says: %Internal DCE Threads problem (version CMA BL10+), terminating execution. % Reason: dispatch: no available VP (uniprocessor) The current thread is 3 (address 0x40107c40) DECthreads... (0 Replies)
Discussion started by: vanz
0 Replies

8. Shell Programming and Scripting

Perl problem

I have been recently given a PERL script to develop, but the main problem is that the perl version that I have to use is old, also I cant download modules from CPAN. Perl version 5.0005 I didnt realise this untill I had the script ready to be tested, so there are a few modules that I have... (6 Replies)
Discussion started by: meevagh
6 Replies

9. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

10. Shell Programming and Scripting

new to perl.. how do I do this ? fork/ threads ?

I have never coded in perl before (just started today morning :). I need to write a perl program to automate a task. Here is how I do it manually: Start a program in my home dir. Now if I want to execute another program while this one is still running, what I would do is go to another... (6 Replies)
Discussion started by: the_learner
6 Replies
Login or Register to Ask a Question