 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Svetlana Roshenko
RE: Process.create( and the environment param [ reply ] 2012-10-12 23:13
|
Hi,
i am sorry for the rape of this dead thread but I can't get this working too and if I understand the current code correctly it still does not work.
Code from process.rb currently says
if hash['environment']
env = hash['environment'].split(File::PATH_SEPARATOR) << 0.chr
if hash['with_logon']
env = env.map{ |e| multi_to_wide(e) }
env = [env.join("\0\0")].pack('p*').unpack('L').first
else
env = [env.join("\0")].pack('p*').unpack('L').first
end
else
env = nil
end
This means that applying an environment with key "Path" and value "C:\foo;C:\bar" will never work properly.
Why
.split(File::PATH_SEPARATOR)
and not
.split(0.chr)
? Any advice would be really helpful :)
A test script could be
require 'win32/process'
process_info = Process.create(
:app_name => ENV['ComSpec'].dup,
:creation_flags => Windows::Process::CREATE_NEW_CONSOLE,
:process_inherit => false,
:thread_inherit => true,
:cwd => "C:\\",
:environment => 'Foo=C:\bar;C:\baz'
)
Process.detach(process_info[:process_id])
|
By: Gavin Jefferies
RE: Process.create( and the environment param [ reply ] 2009-02-02 05:34
|
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
|
By: Gavin Jefferies
Process.create( and the environment parameter [ reply ] 2009-02-01 00:33
|
Hi,
I've been trying to use Process.create with a modified environment. However the PATH environment variable is truncated to its first entry. process.rb expects the environment to be passed in separated by File::PATH_SEPARATOR which is ';' and which is also how the PATH environment var splits up its members.
How should the environment parameter be constructed to support variables with ';' in their value. e.g. PATH and PATHEXT?
Thanks,
Gavin
|
|
 |