Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
Message: 64378
BY: Gavin Jefferies (gj262)
DATE: 2009-02-02 05:34
SUBJECT: RE: Process.create( and the environment param

 

Hi Dan,

Here is an example:

require 'win32/process'

env = 'PATH=C:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS'

proc = Process.create(:command_line => 'CMD.EXE /C SET',
:environment => env)

Process.waitpid(proc.process_id)

Produces:

COMSPEC=C:\WINDOWS\system32\CMD.EXE
PATH=C:\ruby\bin
C:\Perl\site\bin
C:\Perl\bin
C:\WINDOWS\system32
C:\WINDOWS
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS
PROMPT=$P$G

Because process.rb separates the environment parameter by ; the PATH value which uses ; in its value is therefore split into 5 separate environment variable settings as shown.

Using \0 to separate the environment variables as per the docs on MSDN might work better. i.e.

"KEY=VALUE\0KEY2=VALUE2\0KEY3"

Or for a real worldish example:

"PATH=C:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS" +
"\0" +
"PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS"

Hope this is clearer.

Thanks,
Gavin


Thread View

Thread Author Date
Process.create( and the environment parameterGavin Jefferies2009-02-01 00:33
      RE: Process.create( and the environment parameterDaniel Berger2009-02-02 04:47
            RE: Process.create( and the environment paramGavin Jefferies2009-02-02 05:34
                  RE: Process.create( and the environment paramDaniel Berger2009-02-11 20:49
                        RE: Process.create( and the environment paramSvetlana Roshenko2012-10-12 23:13
                              RE: Process.create( and the environment paramDaniel Berger2012-10-19 04:43

Post a followup to this message