470,865 Members | 1,957 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,865 developers. It's quick & easy.

system() to execute a config-file and sending variables to php

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
Jul 17 '05 #1
1 2031
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
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by francescomoi | last post: by
9 posts views Thread by Arpan | last post: by
4 posts views Thread by lukaszmn | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.