in reply to Re^2: system() issue
in thread system() issue

Sorry, you will have to forgive me, I'm biologist with only a little computer knowledge. Here's a bit of code:

#!/usr/bin/perl -w
use strict; &sub1; #generates a text file (rep_set.txt) system('python //macqiime/QIIME/bin/assign_taxonomy.py -i rep_set.txt +-o .'); #generates second txt file &sub2; #reads the second text file

So, all three work on their own, but when I try to run them together, sub2 gives me a blank output even though the first two parts generate the appropriate files. I'm hoping that I am simply using system() wrong... The subroutines simply open a txt file, capture some data from it, and print it out in a different format. I can provide them if need be, but since they work fine individually, I've left them out for simplicity

Replies are listed 'Best First'.
Re^4: system() issue
by wazat (Monk) on Dec 13, 2013 at 06:02 UTC

    See the response from vinoth.ree. system() has a return value. A return value of 0 is good. Other return values indicate various types of problems. One thing you can do is print the value returned by system.

    my $rc = system( 'python //macqiime/QIIME/bin/assign_taxonomy.py -i re +p_set.txt -o .'); print "system returned $rc, \$? is $?\n";

    see the perdoc on system in perlfunc for more details

Re^4: system() issue
by Anonymous Monk on Dec 13, 2013 at 05:49 UTC

    We still don't have enough information. There's no obvious problem. Like vinoth.ree says, try checking for errors. I like to use this pattern with system:

    system(...) == 0 or die;

    Maybe sub2 is failing to open its input file. Always error-check opens as well.

    open FOO, 'foo.txt' or die;

    In a finished script, it's nice to have some kind of error message on the die

    open FOO, '<', $filename or die "Can't open $filename: $!;

    ... but get that or die on there, it can save you a lot of head-scratching.

Re^4: system() issue
by vinoth.ree (Monsignor) on Dec 13, 2013 at 08:08 UTC
    #!/usr/bin/perl -w [download] use strict; &sub1; #generates a text file (rep_set.txt) system('python //macqiime/QIIME/bin/assign_taxonomy.py -i rep_set.txt +-o .'); #generates second txt file if ( $? == -1 ) { print "command failed: $!\n"; } else { printf "command exited with value %d", $? >> 8; } &sub2; #reads the second text file

    Try your script this way of checking the exit status of your python script.


    All is well
Re^4: system() issue
by Anonymous Monk on Dec 13, 2013 at 06:28 UTC

    Also make sure you close your files in sub1.

Re^4: system() issue
by Anonymous Monk on Dec 13, 2013 at 06:01 UTC

    This is kind of dumb, but... you're running this on a network drive? What happens if you put a sleep(10) after the system?