Question

I work on windows 7. I try to execute the Gnuwin32 grep command from within a PHP script like so var_dump(shell_exec("grep")), so I can see if it works or not. Instead of the expected output of usage: and things like that I get null.

  • C:\gunwin\bin is on my Windows path and on the PHP include_path
  • grep works from the command line
  • shell_exec('dir') (or any other 'regular' windows-environment command) works as expected

I'm sure I'm missing something obvious here, but I can not find out what it is. Does anyone have a suggestion?

EDIT: something strange happened. I tried shell_exec('wget'), just for the sake of it. This works as expected. After that, I tried shell_exec('grep --help') and this actually returns the output I expected. I'm a little confused now.

Was it helpful?

Solution

grep, without arguments, writes nothing in stdout, but show two lines (instructing to use --help) on stderr, which is not returned with shell_exec.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top