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:

ยทยทยท

--
Posted via http://www.ruby-forum.com/.

Pranjal Jain 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

ยทยทยท

--
Posted via http://www.ruby-forum.com/\.

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"

ยทยทยท

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")

* Pranjal Jain <pranjal.jain123@gmail.com> (06:29) schrieb:

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

Pranjal Jain 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

ยทยทยท

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

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 Jain <pranjal.jain123@gmail.com> 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")
"

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:
--
Posted via http://www.ruby-forum.com/\.

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

Damjan Rems wrote:

ยทยทยท

Pranjal Jain 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

--
Posted via http://www.ruby-forum.com/\.

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 Jain
<pranjal.jain123@gmail.com>

--
Posted via http://www.ruby-forum.com/\.

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?

ยทยทยท

--
Posted via http://www.ruby-forum.com/\.

Albert Schlef 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 Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

~ There's never enough time to do all the nothing you want.
      -- Calvin