Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

system call not working

by Becky (Beadle)
on Jul 11, 2002 at 12:31 UTC ( #181006=perlquestion: print w/ replies, xml ) Need Help??
Becky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've written a perl program which makes a system call to a program called 'Predator' (for the biologists among you it's a protein secondary structure prediction program). You run Predator from the command line as follows:
/path/to/Predator/predator -foutput_file.txt input_file.txt
where Predator reads from input_file.txt and writes the results to output_file.txt. If you miss out -foutput_file.txt the results are written straight to screen.

My system call in my perl program therefore looks like this:

system "/home/rebecca/bs127/Predator/predator -fpredator.txt input_seq +uence.txt
However, this doesn't work - predator.txt is not created. There's definitely not a problem opening input_sequence.txt, because this is used successfully elsewhere in the program.

Predator works on input_sequence and creates predator.txt when run from the command line.

What could the problem be? I'm assuming it's permissions of some sort, but don't know enough about them to see what. Any ideas?

Comment on system call not working
Select or Download Code
Re: system call not working
by io (Scribe) on Jul 11, 2002 at 12:47 UTC

    you forgot a quote here:

    system "/home/rebecca/bs127/Predator/predator -fpredator.txt input_seq +uence.txt <---

    Im assuming it is right in your script. You could try to use 'backticks' to catch the output:

    my $output = `/home/rebecca/bs127/Predator/predator input_sequence.txt +`; open (FILE, ">predator.txt") or die $!; print FILE $output; close (FILE) or die $!;

    About permissions, has your script got write permissions for the local directory?

    hope it helps

      Or does the user running the script have write permission to the dir?
Re: system call not working
by virtualsue (Vicar) on Jul 11, 2002 at 12:52 UTC
    system returns an exit value. You should try looking at it to see what is wrong.
    system("program -a arg1 -b arg2"); $exit_val = $? >> 8; # or divide by 256 if you like
    A return value of 0 indicates success.

    Have you tried leaving off the -f filename argument as another way to see if the program has successfully been executed by system?

Re: system call not working
by grantm (Parson) on Jul 11, 2002 at 12:54 UTC

    Are you running your script from the command line or from a CGI script? If it's a CGI script, then it will be running with some user ID (eg: nobody, httpd, www) which probably does not have permission to write in the current directory. Try '-f/tmp/output_file.txt' - usually everyone has write access to /tmp

Re: system call not working
by flounder99 (Friar) on Jul 11, 2002 at 13:22 UTC
    This may be a dumb question, but you mentioned:
    There's definitely not a problem opening input_sequence.txt, because this is used successfully elsewhere in the program.
    Did you forget to close the filehandle to input_sequence.txt or leave it (f)locked? I've been bitten by dumb mistakes like that before.

    --

    flounder

Re: system call not working
by Abigail-II (Bishop) on Jul 11, 2002 at 14:31 UTC
    The program will try to create predator.txt in the current working directory. Is that directory what you think it is? Does the program have permission to write in that directory?

    Try using -f/tmp/predator.txt, that is, a full path name and using a directory that is expected to be writable by the program.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://181006]
Approved by virtualsue
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-09-18 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls