[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Passing var to anoter script

Misiek Sz

9/20/2007 2:06:00 PM

Hey,
I'm working on script using Watir class where I want to pass variable of
Watir class to another script and I'm getting an error saying "syntax of
the command is invalid', but when I pass any other variable it works
fine.
Here is my code

Working ex.
main.rb:
$test = 'test'
system("ruby \"popi.rb\" #{$test}")

popi.rb
puts $test unless $test.nil?
puts $ie unless $ie.nil?

Not working ex.
main.rb:
require 'watir'
$ie = Watir::IE.attach(:title,/Appli.*/)
system("ruby \"popi.rb\" #{$ie}")

popi.rb for this is the same.

Any ideas as to why it generates syntax error?
Thanks
--
Posted via http://www.ruby-....

4 Answers

Bertram Scharpf

9/20/2007 5:12:00 PM

0

Hi,

Am Donnerstag, 20. Sep 2007, 23:06:07 +0900 schrieb Michal Sza:
> I'm working on script using Watir class where I want to pass variable of
> Watir class to another script and I'm getting an error saying "syntax of
> the command is invalid', but when I pass any other variable it works
> fine.
>
> Not working ex.
> main.rb:
> require 'watir'
> $ie = Watir::IE.attach(:title,/Appli.*/)
> system("ruby \"popi.rb\" #{$ie}")

This is not a Ruby but a shell issue. Use

system "ruby", "popi.rb", $ie

Further, command arguments may only be strings. If you
really need to do this anyway you could marshal the object:

----sub.rb
class C ; end
c = Marshal.load ARGV.shift
puts c.inspect
----------

----main.rb
class C ; end
c = C.new
system "ruby", "sub.rb", Marshal.dump(c)
-----------

I doubt whether objects that are connected to processes
outside could be marshalled at all.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Misiek Sz

9/21/2007 1:08:00 PM

0

Thanks that was helpful.

Also, how can I pass values back to main script from child
script/process?
--
Posted via http://www.ruby-....

Misiek Sz

9/21/2007 1:17:00 PM

0


>
> system "ruby", "popi.rb", $ie
>
> Further, command arguments may only be strings. If you
> really need to do this anyway you could marshal the object:
>
What I just noticed was that it throws me an error saying that $ie
cannot be converted to string. Why is trying to convert it to string if
it's the 1st arg.?
I don't follow that logic here...
--
Posted via http://www.ruby-....

Bertram Scharpf

9/21/2007 10:25:00 PM

0

Hi,

Am Freitag, 21. Sep 2007, 22:17:22 +0900 schrieb Michal Sza:
> >
> > system "ruby", "popi.rb", $ie
> >
> What I just noticed was that it throws me an error saying that $ie
> cannot be converted to string. Why is trying to convert it to string if
> it's the 1st arg.?

That was what I meant when I wrote this:

> > I doubt whether objects that are connected to processes
> > outside could be marshalled at all.

Arguments to Unix commands are always strings; return value
is always a 1-byte integer where 0 means success.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...