use strict; use warnings; use threads; use threads::shared; main(); sub main { my @arr = ( 'ssh user@host rm -rf /cygdrive/mobile', 'ssh user@host mkdir /cygdrive/mobile', ); foreach my $key(@arr) { my $path = '/home/tart/tmp/'; execute($path, $key); } } sub execute { my $path = shift; my $cmd = shift; chdir($path) || die"Cant change patch $path\n"; my $done :shared = 0; my @out; async { @out = `$cmd &`; if($?) { print "Error: $cmd\n"; } $done = 1; }->detach; until($done) { for(1 .. 20 ) { sleep 1; last if $done; } verbose($cmd); } print "@out\n"; } sub verbose { my $cmd = shift; print "Still executing: $cmd\n"; } #### sub execute { my $infoHR = shift; my $setupHR = shift; my $path; my $command; $path = $infoHR->{PATH}{$setupHR->{list}->{pth}}; $command = $infoHR->{COMMAND}{$setupHR->{list}->{cmd}}; $path =~ s/^\s+//; $path =~ s/\s+$//; $command =~ s/^\s+//; $command =~ s/\s+$//; changeDirectory($path) || die "Unable to change dir to $path\n"; my $done:shared = 0; my $failed:shared = 0; my @systemOut:shared; async { @systemOut = `$command 2>&1`; if($?) { $failed = 1; } $done = 1; }->detach; until($done) { for(1 .. 20 ) { sleep 1; last if $done; } verbose(Running, $command); } unless($failed) { verbose(Success, $command); return 1; } return errFound($setupHR, Error $command); } #### Scalars leaked: 1