I am running a Ruby script which needs to set some environment variables
and then execute non-Ruby programs through Linux and pass the modified
environment to the new processes. It doesn't look as though I can do
this with 'exec', is there a way to do this with existing Ruby
functionality?
On Apr 11, 2008, at 10:57 PM, Ian Peters-campbell wrote:
I am running a Ruby script which needs to set some environment variables
and then execute non-Ruby programs through Linux and pass the modified
environment to the new processes. It doesn't look as though I can do
this with 'exec', is there a way to do this with existing Ruby
functionality?
--
Posted via http://www.ruby-forum.com/\.
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
I am running a Ruby script which needs to set some environment variables
and then execute non-Ruby programs through Linux and pass the modified
environment to the new processes. It doesn't look as though I can do
this with 'exec', is there a way to do this with existing Ruby
functionality?
This doesn't do what you want?
ENV['foo'] = 'bar'
exec "echo $foo" # ==> bar
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
unless fork
ENV.clear # if needed
ENV.update new_env
exec...
end
Kind regards
robert
···
On 12.04.2008 06:57, Ian Peters-campbell wrote:
I am running a Ruby script which needs to set some environment variables
and then execute non-Ruby programs through Linux and pass the modified
environment to the new processes. It doesn't look as though I can do
this with 'exec', is there a way to do this with existing Ruby
functionality?
I believe something like
ENV['foo'] = 'bar'
is enough.
This is not what the OP asked for IIRC. He wanted to modify the environment of a process started from his Ruby program not the program's own environment. This question was likely inspired by the POSIX C function /execle/.
You can try it, compile a small GNU configure program via ruby
ENV['CFLAGS'] = 'O2'
should work, I am quite confident that it will work.
It will likely work but also affect the program's own environment as well as that of all subsequent started sub programs.
I believe something like
ENV['foo'] = 'bar'
is enough.
This is not what the OP asked for IIRC. He wanted to modify the
environment of a process started from his Ruby program not the program's
own environment. This question was likely inspired by the POSIX C
function /execle/.
You can try it, compile a small GNU configure program via ruby
ENV['CFLAGS'] = 'O2'
should work, I am quite confident that it will work.
It will likely work but also affect the program's own environment as
well as that of all subsequent started sub programs.
Kind regards
robert
Yes, apologies if my original question was not clear. I have a Ruby
script which starts a new session D-Bus, and then starts two other
applications which need to be connected to this new D-Bus. I have
control over the source code of one of these applications, and so can
order it to connect to a bus whose address I pass to it at startup. The
second application is effectively a black box though...I can only
control whether it connects to what it believes to be the system or
session bus.
Thus, I need a way to clobber its DBUS_SESSION_BUS_ADDRESS at startup.
I am already setting the ENV value on the parent process, but it is not
passing the modified environment to the process launched via exec().
So...I am looking for a way to push an environment to the "black box"
process while still managing to retain the PID in the parent (as I still
need to be able to signal the "black box."
I hope that is more clear, and any help that people can provide would be
appreciated
I believe something like
ENV['foo'] = 'bar'
is enough.
This is not what the OP asked for IIRC. He wanted to modify the
environment of a process started from his Ruby program not the program's
own environment. This question was likely inspired by the POSIX C
function /execle/.
You can try it, compile a small GNU configure program via ruby
ENV['CFLAGS'] = 'O2'
should work, I am quite confident that it will work.
It will likely work but also affect the program's own environment as
well as that of all subsequent started sub programs.
Kind regards
robert
Yes, apologies if my original question was not clear. I have a Ruby script which starts a new session D-Bus, and then starts two other applications which need to be connected to this new D-Bus. I have control over the source code of one of these applications, and so can order it to connect to a bus whose address I pass to it at startup. The second application is effectively a black box though...I can only control whether it connects to what it believes to be the system or session bus.
Thus, I need a way to clobber its DBUS_SESSION_BUS_ADDRESS at startup. I am already setting the ENV value on the parent process, but it is not passing the modified environment to the process launched via exec().
Are you sure?
robert@fussel ~
$ echo $FOO
robert@fussel ~
$ ruby -e 'ENV["FOO"]="bar";exec("bash", "-c", "echo \$FOO")'
bar
robert@fussel ~
$ echo $FOO
So...I am looking for a way to push an environment to the "black box" process while still managing to retain the PID in the parent (as I still need to be able to signal the "black box."
I hope that is more clear, and any help that people can provide would be appreciated
It was pretty clear to me and I believe I provided a solution already (see my earlier posting).
I believe something like
ENV['foo'] = 'bar'
is enough.
This is not what the OP asked for IIRC. He wanted to modify the
environment of a process started from his Ruby program not the program's
own environment. This question was likely inspired by the POSIX C
function /execle/.
You can try it, compile a small GNU configure program via ruby
ENV['CFLAGS'] = 'O2'
should work, I am quite confident that it will work.
It will likely work but also affect the program's own environment as
well as that of all subsequent started sub programs.
Kind regards
robert
Yes, apologies if my original question was not clear. I have a Ruby script which starts a new session D-Bus, and then starts two other applications which need to be connected to this new D-Bus. I have control over the source code of one of these applications, and so can order it to connect to a bus whose address I pass to it at startup. The second application is effectively a black box though...I can only control whether it connects to what it believes to be the system or session bus.
Thus, I need a way to clobber its DBUS_SESSION_BUS_ADDRESS at startup. I am already setting the ENV value on the parent process, but it is not passing the modified environment to the process launched via exec(). So...I am looking for a way to push an environment to the "black box" process while still managing to retain the PID in the parent (as I still need to be able to signal the "black box."
I hope that is more clear, and any help that people can provide would be appreciated
If you are "permanently" changing the environment have you tried using export to change the setting in the main program?