Ruby win32 and the system call
require 'rubygems'
require 'win32/process'
# win32 system call that returns correct status
def system(cmd)
pid = fork
if !pid
args = cmd.split(' ')
args.first << ".exe" unless args.first.match(/\..+$/)
cmd = args.join(' ')
exec cmd
end
ret = Process.waitpid2(pid)
(ret.last == 0)
end
Update:
If you try using this in a rake task you'll notice an error similar to this:
c:/ruby/bin/rake.bat:1: syntax error, unexpected tIDENTIFIER, expecting $end
To fix this I patched win32/process.rb fork to gsub out rake.bat with rake, since this is a pretty specific case within win32 ruby.
Here's the line.
cmd.gsub!(/rake.bat/,'rake')
rv = CreateProcess(0, cmd, 0, 0, 1, 0, 0, 0, startinfo, procinfo)
Just before the call to CreateProcess line 565 for win32-process 0.5.3
Update:
It looks like the above is the result of how the one click installer uses .bat files. Upgrading Rake to 0.7.3 and the patch is no longer needed in win32-process.


Recent Comments