in reply to system() issue

Any suggestions?

Boil it down to the smallest possible test case that demonstrates the behavior you're describing, and post that code here. Keep it to less than 40 lines of code (I usually say less than 20, but you've got several moving pieces, and that complexity might warrant 40 lines to demonstrate).

Code is needed, otherwise we can only guess. We don't necessarily need to see your program. We just need to see a small example that is complete enough to compile and demonstrate the behavior, while eliminating anything unrelated to the problem.


Dave

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

    davido is right. You need to provide more information than the vague description you gave.</P.

    It sounds like you have only taken the first steps in troubleshooting your problem. Do you test the return value from system() to determine if it ran successfully? Are you using of system() properly? What do you know about the python program's execution when run via system()?

    We can't help you with so little information.

      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

        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

        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.

        #!/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

        Also make sure you close your files in sub1.

        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?