
C4zz3o
New User
Nov 21, 2011, 9:41 AM
Post #1 of 1
(166 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:
#!/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: and After 10 seconds have
Hello Word after 10 seconds Thanks Paz
|