Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there.

I have a problem with a perl script I am running. The script works perfectly from the command line, but when I try to look at it from a web page, it goes wrong.

I have managed to isolate the command that is causing this. It is this:

 system('/usr/local/bin/dcm_dump_file -t '.$n.' > '.$dump_path.'PCfiles/dumpfile');

($n is a string relating to a particular file name, which is iterated over a foreach loop. The command basically breaks off into Unix, executes a dicom dump file, and writes the output to a file called 'dumpfile')

The question is, is the syntax correct for my system call?
Should I be doing something else to get this to work from a web page?

Thanks in advance,

C

Replies are listed 'Best First'.
Re: system call
by Zaxo (Archbishop) on May 10, 2004 at 13:18 UTC

    Chances are that the httpd user doesn't have write permission for the directory where you try to create the file. You can either change permissions, or else look into suExec (if Apache httpd).

    What does your error log say?

    After Compline,
    Zaxo

Re: system call
by haoess (Curate) on May 10, 2004 at 13:24 UTC

    You didn't tell us, what goes wrong.

    Your code is syntactical correct. But:

    • Where does $n come from?
    • Where does $dump_path come from?

    They may contain special shell characters like &, ;, `, ', ", |, *, ?, ~, <, >, ^, (, ), [, ], {, }, $ and \.

    Your CGI-script mostly does not run under the same UID as your command line script, so you should think of:

    • Is your "CGI"-user able to execute /usr/local/bin/dcm_dump_file?
    • Does "he" have enough rights to write into $dump_path.'PCfiles/dumpfile'?

    To examine your situation, you should look at possible errors and use backticks with redirecting STDERR to STDOUT:

    # see what happens print `$your command 2>&1 > output`;

    -- Frank

Re: system call
by Roger (Parson) on May 10, 2004 at 13:22 UTC
    Your problem is most likely to do with permissions. Remember that your script when running in CGI mode, is under the apache/httpd user, not your normal user. Make sure the dump path directory is writable to the apache user. You should be able to see the type of error in your web server log.

    Your system call looks ok to me. There is a better way to write it:
    system "/usr/local/bin/dcm_dump_file -t $n > $dump_path/PCfiles/dumpfi +le";

    Notice the use of double quotes instead of single quotes. Perl interpolates the variables inside the double quote.

Re: system call
by Tomte (Priest) on May 10, 2004 at 13:18 UTC

    Check if the user running the webserver is running under has the neccesary rights to execute dcm_dump_file.

    Erros like these (runs on the cmdl, not via my webserber) are most of the time permissions-issues...

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

Re: system call
by Juerd (Abbot) on May 10, 2004 at 13:20 UTC
Re: system call
by Anonymous Monk on May 10, 2004 at 14:06 UTC
    Thanks, people.

    I changed the permissions, and it worked.

    Also, the fact that it 'goes wrong' wasn't what the problem was. I was very specific about the fact that my system call wasn't working from a web page, but that it was working from the command line.

    So no sarcastic comments, please!

      Explaining actual behavior instead of "it was broke" will go a long way to getting actual help from anybody. How to ask questions the smart way.

      --
      [ e d @ h a l l e y . c c ]