Passing var to anoter script

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

Hi,

Am Donnerstag, 20. Sep 2007, 23:06:07 +0900 schrieb Michal S.:

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©

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

Bertram

Thanks that was helpful.

Also, how can I pass values back to main script from child
script/process?

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…

Hi,

Am Freitag, 21. Sep 2007, 22:17:22 +0900 schrieb Michal S.:

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