On Thu, 13 May 2004 17:34:14 +0200, Arne Lund wrote:
I've to read variables out of a config-file, that is stored on a
Linux-machine.
When I connect to the server with puTTY, I can execute the config with:
. /usr/local/webspace/config
then I can echo the contained variables:
echo $var1
everything works fine.
Now I want to execute the config by a php-script.
I try to open the file with the system() command:
system('. /usr/local/webspace/config', $retval);
I hoped to get the same variables now for doing some stuff with them in php.
But there are no variables, but the $retval = 0
Any ideas?
Arne Lund
The problem is that $retval returns the return value of the script,
_not_ the output of the script. To get the output, do this:
$output = system('. /usr/local/webspace/config', $retval);
Many Unix programs set a return value after executing. For example, if you
use 'grep', it returns a '0' if it was successful, '1' if not. Let's say
'ls' returns this:
..
...
readme.txt
foo.c
Now 'ls | grep foo.c' returns
foo.c
and grep has set the return value to '0'. To get the return value, you can
use 'echo $?' at the shell prompt after executing the above command. If
you do 'ls | grep file.txt', the output is nothing, but the return value
of grep will be '1'.
So when you were getting a '0' for $retval, that meant that your script
executed successfully with a return status of '0'.
DrTebi