Archive

Posts Tagged ‘Win32’

Ruby win32 and the system call

September 15th, 2007
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.

Software ,

Proc Tell

August 20th, 2006

I was looking at my win32 machine tonight and realized I didn’t know what a few of the processes I had running were. I googled them and decided it would be really nice if I i didn’t have to type the process name into google. ProcTell is a little XULRunner app that will list all running processes and a google search box. When double clicking on one of the process in the list it runs a google search query in a browser frame.

Try it out

Software ,