2

I'm trying to run some windows command line calls in the same system process using a Ruby Rake task. I need to find the way to do the calls correctly and this calls can't be dependent on each other.

I know that the 'fork' function can be a solution, but it doesn't work in Windows. I tried with other functions, like IO.POPEN and Process.spawn and I didn't find a real solution.

I'm working with Ruby 1.9.3 in windows XP.

task :CmdTest,:value do |t, args|
  value=args.value.to_s
  begin

    $cmd<<("set MYVAR=#{value}")
    $cmd<<("set MYVAR")
    $cmd<<("exit")
  rescue Exception => e
    puts e.message
  end
end

task :CmdTest3 do

  IO.popen("cmd", "r+") do |io|
    th = Thread.new(io) do |chan|
      chan.each {|line| puts line}
    end
    $cmd.each do |f|
      io.puts f
    end
    io.close_write
    th.join
  end
end

1 Answer 1

1

Take a look at win32utils, is that what you are after?

Sign up to request clarification or add additional context in comments.

1 Comment

I will have a look at that link and see if it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.