Dear Monks,

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:

my $command = "bp_genbank2gff3.pl -y -o out_dir some_genbank_filename" +;
(replace out_dir and some_genbank_filename with real names)

Now, any of these will work fine (the files will be created in the output dir):

run_command( $command, 1, undef ); run_command( $command, 0, "some_file_name"); run_command( $command, 1, "some_file_name");
but this will not work (no error but also no files created):
run_command( $command, 0, undef );
Why? It's as if the script knows whether I'm keeping track of it's stdout.

Thank you, Dave


In reply to Problems executing a (bioperl) script from another script by daverave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.