Mikael Høilund
5/5/2008 6:10:00 AM
On May 5, 2008, at 6:29, Pranjal Jain 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 =20=
means that when you run it, you're essentially put back to square one; =20=
all the environment variables and information about the current shell =20=
is reset =97 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 =20
directory. This is my output:
Shell 1:
/
Shell 2:
/Users
Shell 3:
/
See, in the first shell it's in the directory "/" (the rough =20
equivalent of C:\ on Windows).
In the second shell, I change to the directory "Users", and display =20
the directory; it's in "/Users".
Now, when I run the third, it's returned to "/" because it has =20
launched a new shell, not reused the old one. Any change to the =20
environment of one system method call isn't going to affect subsequent =20=
calls.
To do what you want to do (untested, as I haven't got access to a =20
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 =20
doing what you want. If the ruby script you're calling isn't referring =20=
to any files with a relative path (the directory from which it's =20
called doesn't matter), you could just do
system "ruby D:\ruby\Temp"=