in reply to running process from CGI

I suggest you contact the third party supplier and ask them how the directory is chosen. It is unusual for a program to write to a directory from which it is invoked - usually programs write to the current directory, which of course is not the same thing. I'm not sure what you mean by "tend to", do they or do they not? If they are writing to the current directory then just call chdir.
You might be able to work-around it by pre-creating the filename as a symbolic link to the real directory (or even to use a named pipe/fifo). That won't work if the program destroys the file and re-creates it.

Replies are listed 'Best First'.
Re^2: running process from CGI
by kota_rocks (Initiate) on Apr 12, 2007 at 11:52 UTC
    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.
      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.