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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


New User

Nov 21, 2011, 9:41 AM

Post #1 of 1 (713 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

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

So I wrote the following perl script:


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) {

#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:

 Hello Word

and After 10 seconds have

 Hello Word after 10 seconds




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

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