use strict; use threads; use threads::shared; sub SystemCall { my $call = join ' ', @_; local $| = 1; # run hot pipes print "Executing system call '$call'"; # Start a thread to print out dots indicating that Perl hasn't hung my $thread_beat = 0.1; # Should be small, but not so small as to flood the screen with dots. my $stop :shared = 0; my $thread = threads->create( {'context' => 'void'}, sub { while ( not $stop ) { print '.'; select( undef,undef,undef, $thread_beat ) } }); $thread->detach(); # Run the command my $result; eval { chomp( $result = `$call` ) }; warn $@ if $@; # eval failed. # Signal the thread to end. $stop = 1; # And wait one beat for the thread to end. select( undef,undef,undef, $thread_beat + 0.01 ); print $/; # Present error message status, if any. warn "\$? = '$?'\n" if defined $? and $?; warn "\$! = '$!'\n" if defined $! and $!; warn "\$@ = '$@'\n" if defined $@ and $@; warn "\$^E = '$^E'\n" if defined $^E and $^E; warn "\$^W = '$^W'\n" if defined $^W and $^W; if ( $result ) { print $result, $/ } return defined $result ? $result : ''; }