use Expect; my ($program_name, $login, $sourcefile) = @_; #spawn program_name using perl expect module my $exp = Expect->spawn($program_name,$login) or die "Cannot spawn $program_name $login: $!\n"; #turn off output of results from stdout $exp->log_stdout(0); # wait for program_name to initialise $exp->expect(600,[ qr/Program ready to start/]); # send appropriate command to program_name $exp->send("run program_name $report_name $output_format $sourcefile \n"); # Wait for report to run or generate an error $exp->expect(600,[ qr/Error/i, sub { my $self = shift; $self->send("quit\n"); print ("perl_program.pl has found an error: $_ \n"); exp_continue; }], [ qr/Report run successful./i, sub { my $self = shift; $self->send("quit\n"); exp_continue; }]); }