On May 5, 2008, at 6:29, Pranjal J. wrote:
require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)
Whenever you run the system method, you’re making a new subshell. This
means that when you run it, you’re essentially put back to square one;
all the environment variables and information about the current shell
is reset — including the current directory. Example:
puts “Shell 1:”
system ‘pwd’
puts
puts “Shell 2:”
system ‘cd Users; pwd’
puts
puts “Shell 3:”
system ‘pwd’
This runs on my Mac computer. The pwd command displays the current
directory. This is my output:
Shell 1:
/
Shell 2:
/Users
Shell 3:
/
See, in the first shell it’s in the directory “/” (the rough
equivalent of C:\ on Windows).
In the second shell, I change to the directory “Users”, and display
the directory; it’s in “/Users”.
Now, when I run the third, it’s returned to “/” because it has
launched a new shell, not reused the old one. Any change to the
environment of one system method call isn’t going to affect subsequent
calls.
To do what you want to do (untested, as I haven’t got access to a
Windows machine at the moment), you’d have to do something like:
system “D:; cd ruby\Temp; ruby trial.rb”
This keeps all the calls in the same shell, which is a necessity for
doing what you want. If the ruby script you’re calling isn’t referring
to any files with a relative path (the directory from which it’s
called doesn’t matter), you could just do
system “ruby D:\ruby\Temp”