Problem using System command in ruby

HI All

I am using WIndows gem “winclicker” to run windows properties.

The code is as follows:
"
require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)
"

I am trying to run file trial.rb via this script. but it is giving me
the error as follows :

The system cannot find the path specified.
ruby: No such file or directory – trial.rb(LoadError)

PLease tell me wht is wrong in the code.

Thanks in advance :slight_smile:

Pranjal J. wrote:

HI All

I am using WIndows gem “winclicker” to run windows properties.

The code is as follows:
"
require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)
"

Maybe:
system (“cd \ruby”)

by
TheR

Hi there
It is not working.
I think some different command is required.

Damjan R. wrote:

Pranjal J. wrote:

HI All

I am using WIndows gem “winclicker” to run windows properties.

The code is as follows:
"
require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)
"

Maybe:
system (“cd \ruby”)

by
TheR

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”

Pranjal J. wrote:

require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)

Dir.chdir(“d:/ruby/Temp”) {system(“ruby trial.rb”)}

HTH,
Sebastian

require ‘watir/winClicker’
system (“D:”)
system (“cd ruby”)
system (“cd Temp”)
system (“ruby trial.rb”)

That won’t work because each system command runs in its own shell
process. A ‘cd’ has no effect on later commands.

mfg, simon … l

Hey there Pranjal J.,

as by Sebastian’s example, I’d also suggest you to use
ruby’s way to change directory (via Dir.chdir).
IMHO it is always better to (try to) use ruby commands rather
than shell specifics.

Have you verified that the trial.rb file is located in teh saem
directory
that you are running the “system (“ruby trial.rb”)” from?

system(“ruby trial.rb”) should be run from the same directory as the
trial.rb script. For instance, if you attempt to run this script from
the
drive root of c:\ and the trial.rb script resides in
c:\mycoolrubyscripts\testscripts\

Let me know if thats teh problem, if not I can give it another stab.

On Sun, May 4, 2008 at 11:29 PM, Pranjal J.
[email protected]

HI there
Yes it is in the same directory

princeofnigeria wrote:

Have you verified that the trial.rb file is located in teh saem
directory
that you are running the “system (“ruby trial.rb”)” from?

system(“ruby trial.rb”) should be run from the same directory as the
trial.rb script. For instance, if you attempt to run this script from
the
drive root of c:\ and the trial.rb script resides in
c:\mycoolrubyscripts\testscripts\

Let me know if thats teh problem, if not I can give it another stab.

On Sun, May 4, 2008 at 11:29 PM, Pranjal J.
[email protected]

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.

That’s true for posix systems, that the ‘current directory’ is
independent for each process.

But, AFAIK, this isn’t correct for Windows. Has this changed with newer
versions of Windows?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Albert S. wrote:
|
| That’s true for posix systems, that the ‘current directory’ is
| independent for each process.
|
| But, AFAIK, this isn’t correct for Windows. Has this changed with newer
| versions of Windows?

Windows XP SP2 exhibits that behavior. And this is more something on
Ruby’s side of things, rather than the OS (that can do little, after
all, if Ruby works its magic, no?), especially if this behavior is
consistent across platforms (which I’m too lazy to check, but somebody
with *NIX currently booted can do that easily ;).


Phillip G.
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

~ There’s never enough time to do all the nothing you want.
– Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgfGCoACgkQbtAgaoJTgL85tgCfe8NE4Kv7ciqca1SaHVfNu0Ac
NYUAoIT1/E+k4KgUXenjHF8Kl20hIRvT
=9KGO
-----END PGP SIGNATURE-----