in reply to Re: CGI Script Calling Grep
in thread CGI Script Calling Grep

Not recommended for certain values of $string... (scain probably knew that, but some people might not.)

Your exec didn't do what you want because... well, that's not what exec does. It doesn't capture output. Read the docs on exec, system, and backticks (``) for a better understanding. It would be safer and faster to do this using File::Find and Perl's built-in pattern matching.

Replies are listed 'Best First'.
Re: Re: Re: CGI Script Calling Grep
by kjherron (Pilgrim) on Sep 26, 2001 at 10:01 UTC
    Your exec didn't do what you want because... well, that's not what exec does. It doesn't capture output. Read the docs on exec, system, and backticks (``) for a better understanding.

    Actually, he's running grep in a reasonable way. The open() call sets up a pipe, forks, and hooks the pipe to the child process's stdout; he then execs grep in the subshell. The way he's exec'ing grep, he also avoids the question of shell metacharacters in the $string variable.

    Scain: The problem may be the script's current directory. The script is running grep (recursively) on ".". When you run the script by hand you could be starting it in the directory you want grep to search. The web server probably starts the script with a different directory as its current directory, so your script would have to chdir() to the right spot, or else give the full /path/to/the/directory instead of using ".".

      Oh, good point. I assumed he wanted to format the output as HTML.