in reply to CGI and Backticks

nothing is reported back to the script.

This is a bit vague. Can you show a bit more of the context in which the backticks are used? What is the value of $? immediately after the backticks expression is run?

You don't say what your web server is. Some record output to STDERR in their error logs, others discard it. If you are using one of the ones that saves it, you can see what the output of your script was by checking your error logs.

When I am running a CGI script on a web server that doesn't do what I want with STDERR I redirect it myself, to a file that I can review to find out what happened.

Replies are listed 'Best First'.
Re^2: CGI and Backticks
by agronbach (Novice) on Aug 30, 2011 at 00:38 UTC

    As to the 1>&2, I'm not sure why it works, but it works the way that I've posted it. I know its backwards, I'm just running with it for right now.

    As to the problem; I've sort of fixed it. Hopefully this won't be overly confusing, but basically I have my test script which is calling a script that forks a child and has the parent return BEFORE the child. Odd, I know, but for reasons I won't get into here, it has to be that way.

    I played around with things, and it turns out that in dashboard.pl, I have the child process redirect its STDOUT and STDERR to a file and this was masking them, but ONLY from the web, not from a terminal. Either way, I have a flag now that the test script passes which overwrites this redirect. Again, not the best solution but it works for now.

    The error logs cannot be obtained from my web server unfortunately, as I am merely one of many, many users on it. I want both STDERR and STDOUT to report back to my script.

    I should probably make a new thread for this, but does anyone know how to see if a child process has finished? I know I can check the pid of the parent, but how do I get the child's? My problem is now that the test script is waiting for the backticks to finish, and when dashboard's parent exits BEFORE the child does, the test script moves on to the next test case, and the previous child's output (STDOUT and STDERR) are getting jumbled with the next test's outputs.

    Thanks in advance for the help, and sorry if you found this wordy/confusing.

      There are several ways you can get both STDERR and STDOUT from a sub-process. perlipc covers some of them. There are also various process management modules available from CPAN that you might consider.

      You can use kill to check whether a process is running or not, but you would need the process ID for that - you could add it to the output of dashboard.pl.

      You may be able to use waitpid to wait for all processes in the process group to finish, if your system supports this.