| 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 | |