[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem using System command in ruby

Pranjal Jain

5/5/2008 4:29:00 AM

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

9 Answers

Damjan Rems

5/5/2008 5:29:00 AM

0

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-....

Pranjal Jain

5/5/2008 5:35:00 AM

0

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-....

Mikael Høilund

5/5/2008 6:10:00 AM

0


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

Simon Krahnke

5/5/2008 6:34:00 AM

0

* 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

Sebastian Hungerecker

5/5/2008 7:13:00 AM

0

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

princeofnigeria

5/5/2008 12:42:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

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

Pranjal Jain

5/5/2008 1:20:00 PM

0

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-....

Albert Schlef

5/5/2008 2:13:00 PM

0

> 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-....

Phillip Gawlowski

5/5/2008 2:23:00 PM

0

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

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.bl...

~ 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....

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