in reply to Re: running process from CGI
in thread running process from CGI

Thanks for the suggestion cdarke. I think i didnt put it properly. I meant that the third party program writes to the current directory. for example, if i invoke the program as
../../progs/<programname> <options> <parameters>
it writes to the current directory. I tried using chdir() and it partially solves the problem. There are two scripts written in Fortran, which i call in succession. The first one writes output to the required directory when i use chdir() and the other one does not. The third party one needs user intervention at runtime. I tried writing the required values to a file and giving that as an input during invocation as follows
../../progs/<script> < <param input file>
where <param input file> contains different runtime parameters. This works like a charm when i use it on the command line and it does not work when i use it within backticks from the CGI script after issuing a chdir() to the required working directory.

Replies are listed 'Best First'.
Re^3: running process from CGI
by cdarke (Prior) on Apr 12, 2007 at 12:30 UTC
    OK, different problem now. When you say 'it does not work' when used in backticks, is the file created in the wrong directory, or does it fail to read the input?
    It could be that the chdir is affecting the redirection. This will be done by the bourne shell. Try providing the full path name of the input file with your redirection.
    Failing that, you could try:
    `cd $target;../../progs/<script> < <param input file>`
    You are invoking a shell anyway (because of the redirection) so adding a cd won't be any more of an overhead.
    If you still have problems then we could run it in a pipe, which is much neater.
      Well ! That is more or less what i had been doing. These are relelant lines from my CGI script.
      `echo -e "$pdbdir\n$pdbdir/$pdbid.new\n" > $pdbdir/hbopt`; `cd $pdbdir ; $progpath/hbplus/hbplus < $pdbdir/hbopt`;
      i'm writing the required input parameters to the file 'hbopt' in the relevant directory. This file is being created without problems. Then i invoke the script as shown by the second line of code. This program either does not run at all, or does not create output file anywhere. There are no error messages in my apache error logs.
        Test $? after the backticks commands and output "$!" if non-zero. You might also try running the cgi script from the command line.