CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Execute ksh script from perl

 



C4zz3o
New User

Nov 21, 2011, 9:41 AM

Post #1 of 1 (354 views)
Execute ksh script from perl Can't Post

Hello everybody,

I should execute a ksh script from perl and capture and use in real time the output inside the perl script.

I know that I could execute the ksh script in perl using the back-quotes (`).
Now if I use this way I should wait the end of the execution of the script to see the outputs of my script.
So I decide to write the perl script using the threads, but I have a problem: I am not able to see nothing in the output.

For example my ksh program is the following test.ksh

Code
echo "Hello Word" 
sleep 10
echo "Hello Word after 10 seconds"


So I wrote the following perl script:

Code
#!/usr/bin/perl 

use strict;
use warnings;
use threads;

#Shared variable used in both threads

my @test : shared;
#Thread to execute the ksh program
my $thr1 = threads->new(\&execute_ksh);
#Thread to read the array
my $thr2 = threads->new(\&read_array, @test);

my @thr = ($thr1, $thr2);

#Join dei threads

for (@thr) {
$_->join();
}


#Sub to execute the ksh script
sub execute_ksh {

@test = `/path/test.ksh`;

}

#Sub to read the array
sub read_array {
while (@_) {
print $_;
}
}


The output is nothing...could you help me?

I would like to have in the end the following output:

Code
 Hello Word

and After 10 seconds have

Code
 Hello Word after 10 seconds


Thanks

Paz

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives