daverave has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to execute bp_genbank2gff3.pl (bioperl) from inside a perl script. I just need it to convert a file between formats and I don't read the resulting files later in my script, but pass them to a java program. This is why I think it's OK to execute this script as-is (generally, I guess it would be "prettier" to call some bioeprl subroutine that does the same job as the script does, but I couldn't find a simple one).
Anyway, I am using a general helper subroutine that I wrote (run_command) as described below.
use strict; use warnings; use Cwd; use 5.010; # run command and print output to stdout, file, both or none. # $print_to_stdout is boolean, $output_filename is optional sub run_command { my ( $command_string, $print_to_stdout, $output_filename ) = @_; say "### run_command (from ", getcwd(), " ): ", $command_string, " ### +"; # create output file if needed my $output_fh; if ( defined $output_filename ) { open $output_fh, '>', $output_filename or die "can't open $output_filename: $!"; print $output_fh "### run_command: ", $command_string, " ###\n"; } # execute command open( my $command_out, "-|", $command_string ); if ( $print_to_stdout || defined $output_fh ) { while (<$command_out>) { print if ($print_to_stdout); print $output_fh $_ if ( defined $output_fh ); } } close $command_out; # wait until command has finsihed close $output_fh if ( defined $output_fh ); }
And define:
(replace out_dir and some_genbank_filename with real names)my $command = "bp_genbank2gff3.pl -y -o out_dir some_genbank_filename" +;
Now, any of these will work fine (the files will be created in the output dir):
but this will not work (no error but also no files created):run_command( $command, 1, undef ); run_command( $command, 0, "some_file_name"); run_command( $command, 1, "some_file_name");
Why? It's as if the script knows whether I'm keeping track of it's stdout.run_command( $command, 0, undef );
Thank you, Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems executing a (bioperl) script from another script
by jethro (Monsignor) on Aug 13, 2010 at 10:53 UTC | |
by daverave (Scribe) on Aug 13, 2010 at 11:22 UTC | |
|
Re: Problems executing a (bioperl) script from another script
by daverave (Scribe) on Aug 13, 2010 at 12:42 UTC | |
by graff (Chancellor) on Aug 14, 2010 at 05:37 UTC |