views:

205

answers:

1

The following code is in a file called run.rb, the idea is to run ruby as a different user so I can do some testing.

require 'rubygems'
require 'win32/process'

domain = 'WORLDWIDE'
user_name = 'user'
password = 'password'
rubyScript = 'ruby test.rb'
Process.create(:command_line => rubyScript, :domain => domain, :with_logon => user_name, :password => password, :close_handles => false)

the contents of test.rb is:

require 'rubygems'
require 'watir'

browser = Watir::IE.new
browser.goto('http://localhost:44001/Users/List')
puts browser.text

when I run 'ruby run.rb' a command shell opens and then closes straight away. Any ideas what I am doing wrong here?

A: 

It's probably running your command just fine, opening a new command window (since it's a new windows Process), then closing that window when it completes. Try throwing a "sleep 1000" at the end of test.rb. If I'm correct, that should keep the window around so that you can view the output.

Trotter
Putting in the sleep has no effect.If the code had have run, it would have opened an IE instance which I probably would have noticed :)
Derek Ekins