Page 1 of 1

Executing a command line program and getting output

Posted: Fri Sep 26, 2003 9:17 am
by nauman73
Hi!

I am using exec() function to execute a command line porgram on my Windows machine. I want o get the output from execution and parse it. I pass an array to exec() function. An example call is:

Code: Select all

<?php
exec("dir", $output, $ret);
?>
Of course I am not using the "dir" command in my code.

My problem is that when the command executes properly and returns a code value of 0, the $output array is populated, just what I wanted. However, when the execution is unsuccessful and a code value of 1 is returned, $output array does not get populated. Unsuccessful execution of the same command from Command Prompt shows some kind of error message as output. I was expecting that exec() will copy that output in $output array, just like it does when execution is successful.

Looking for any help.

Thanks
Nauman