Passing var to anoter script

M

Michal Sza

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
 
B

Bertram Scharpf

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
 
M

Michal Sza

Thanks that was helpful.

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

Michal Sza

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

Bertram Scharpf

Hi,

Am Freitag, 21. Sep 2007, 22:17:22 +0900 schrieb Michal Sza:
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:

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

Bertram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top