from REALbasic > Terminal > RUBY ?!

W

Watanabe Carcass

Hello:

This might seem weird, I just started Ruby, so don't know much about it,
HOW CAN I PASS ARGUMENTS AS A STRING FROM A UNIX TERMINAL INTO A RUBY
SCRIPT?

I'm developing an application with REALbasic(why?!, because I already
own a license and with REALbasic I can develop and application that can
run natively on OS X without the need of installing extra
libraries(wxCode, wxRuby, etc(problems with building and deploying)) and
using just the Ruby language installed by default on OS X), I would like
to use also RUBY to process ALL the text that comes from Editfields in
REAL.

I already did this "hello world" test and it's working, at least one
way. In this sample you have a window, an editfield and a pushbutton,
once the pushbutton is pressed, it executes a rubyscript and return its
result to be displayed on the editfield. The REAL code is:

Dim s as New Shell
Dim cmd as String
#if TargetMacOS or TargetLinux and Not( TargetMacOSClassic)
cmd="cd /Applications/hello-ruby ; ruby hello.rb"
#elseif TargetWin32
cmd="set"
#endif

s.execute cmd
if s.errorCode=0 then
EditField1.text=s.Result
else
EditField1.text="Error "+ Str(s.ErrorCode)
end if


If you are not familiar with REAL, in this sample I'm using a SHELL
class that can be used to execute Unix or DOS shell commands under
Windows, Mac OS X, or Linux, so in the OS X terminal runs [cd
/Applications/hello-ruby ; ruby hello.rb] and inside the ruby script
there is a simple

puts "Hello World!"

which is returned to the editfield in the REAL interface and displayed.
NOW! I would like to make another sample that could work in the other
way also, so let's suppose I have 3 editfields and a pushbutton, in
editfield1 I enter "hello", next in editfield2 "world!", once the button
is pressed the editfield3 displays the result "hello world!" which was
concatenated in a ruby script.

From the Shell class of REAL I would have to send the strings into the
terminal using ECHO, then How I pass them into the ruby script from the
terminal to be processed?
 
B

Bino Oetomo

Watanabe said:
Hello:

This might seem weird, I just started Ruby, so don't know much about it,
HOW CAN I PASS ARGUMENTS AS A STRING FROM A UNIX TERMINAL INTO A RUBY
SCRIPT?

I did this ... well not a topnotch one.
I'm playing with ttyctrl --> http://ttysctrl.sf.net
This "small" utility will read the status of COMport and do some defined
action ... and I want that this "action" recognized by a runing ruby
script.

For this ... I make a temporary file in my ramdisk ..
Tell ttyctrl to write a string based on witch button-press read by it.
In a noher process, I have a running ruby script that loop to read the
file above .. and do further action based on it content.
In My case .. the ruby script will send content of that file to another
process in another mechine via XMPP (here is where XMPP4R do the trick)
I'll use same trick to send NMEA sentences from one mechine to another
for further process (Map ?)

But .. I think if you have better knowledge than me ... you can use
RubyD
Or basicaly ... let that two application talk eachother via unix socket.

Sincerely
-bino-
 
W

Watanabe Carcass

But .. I think if you have better knowledge than me ... you can use
RubyD
Or basicaly ... let that two application talk eachother via unix socket.

Certainly don't have better knowledge, I have no idea what you are
talking about, je je je.
Something simpler to understand...?

Thanks anyway for your reply!!
 
P

Peña, Botp

T24gQmVoYWxmIE9mIFdhdGFuYWJlIENhcmNhc3M6DQojIEhPVyBDQU4gSSBQQVNTIEFSR1VNRU5U
UyBBUyBBIFNUUklORyBGUk9NIEEgVU5JWCBURVJNSU5BTCBJTlRPIEEgUlVCWQ0KIyBTQ1JJUFQ/
DQoNCnRoaXMgaXMganVzdCBvbmUgc2ltcGxlIHN0dXBpZCBleGFtcGxlLiB0aGVyZSBhcmUgbWFu
eSB3YXlzLg0KDQpyb290QHBjNGFsbDp+IyB1bmFtZQ0KTGludXgNCg0Kcm9vdEBwYzRhbGw6fiMg
Y2F0IHRlc3QucmINCng9Z2V0cw0KcHV0cyAieW91IHBhc3NlZDogI3t4LnVwY2FzZX0iDQoNCnJv
b3RAcGM0YWxsOn4jIGVjaG8gdGhpcyBpcyBhIHRlc3QgfCBydWJ5IHRlc3QucmINCnlvdSBwYXNz
ZWQ6IFRISVMgSVMgQSBURVNUDQoNCg==
 
W

Watanabe Carcass

On Behalf Of Watanabe Carcass:
# HOW CAN I PASS ARGUMENTS AS A STRING FROM A UNIX TERMINAL INTO A RUBY
# SCRIPT?

this is just one simple stupid example. there are many ways.

root@pc4all:~# uname
Linux

root@pc4all:~# cat test.rb
x=gets
puts "you passed: #{x.upcase}"

root@pc4all:~# echo this is a test | ruby test.rb
you passed: THIS IS A TEST

Thanks!! it may be just what I needed.
 
B

Bino Oetomo

Watanabe said:
Certainly don't have better knowledge, I have no idea what you are
talking about, je je je.
Something simpler to understand...?

Thanks anyway for your reply!!

Honestly .. I also a dumb newbie in ruby world .. thats what I mean..
I Assume you played with REAL quietwell .. and I hope you can do socket
programming with it.
If So .. you will be easy to learn to write socket programming with
ruby.
Here is a realy good simple start point for it :

http://sitekreator.com/satishtalim/socket_programming.html

Thanks to you .. your question make me find this url .. and thinking to
switch my curent methode (mentioned in previouse post) to socket
methode.

Somehow we share the same "dream"

Sincerely
-bino-
 
W

Watanabe Carcass

Bino said:
Honestly .. I also a dumb newbie in ruby world .. thats what I mean..
I Assume you played with REAL quietwell .. and I hope you can do socket
programming with it.
Somehow we share the same "dream"

Sincerely
-bino-

Actually I just know the basics of REALbasic and Ruby, but I started to
wonder about "things that seem obvious", maybe they are not. But If
"Ruby is a scripting language" and REALbasic can call scripts, why not
give it a try. Maybe is just nonsense, but you never know.

I'm not a programmer, my relation with computers is far away from being
it, but maybe this "ignorance" gives me a new approach.

Yeah, maybe we share the same dream.
 
B

Brian Candler

This might seem weird, I just started Ruby, so don't know much about it,
HOW CAN I PASS ARGUMENTS AS A STRING FROM A UNIX TERMINAL INTO A RUBY
SCRIPT?

For small arguments you can stick them on the command line, and they will be
available in the array ARGV. But if those arguments contain spaces you'll
have to be careful with quoting.

$ cat x.rb
puts "arg 0 = #{ARGV[0]}"
puts "arg 1 = #{ARGV[1]}"
$ ruby x.rb foo "bar baz"
arg 0 = foo
arg 1 = bar baz
 
W

Watanabe Carcass

Finally!!!

This simple test is working as follow:

Dim s as New Shell
Dim cmd as String
Dim t1 as String
Dim t2 as String

t1 = EditField1.Text
t2 = EditField2.Text

#if TargetMacOS or TargetLinux and Not( TargetMacOSClassic)
cmd="cd /Applications/hello-ruby ; ruby ruby-test.rb " + "'"+t1+"'"
+ " " +"'"+t2+"'"
#elseif TargetWin32
cmd="set"
#endif

s.execute cmd
if s.errorCode=0 then
EditField3.text=s.Result
else
EditField3.text="Error "+ Str(s.ErrorCode)
end if


Yeah I know the multiple quotation marks looks awkward in the cmd...
line but it was the only thing that I came up with to allow the terminal
passing the t1 and t2 strings when these have have more than one
word(spaces in between).

The ruby script [ruby-test.rb] puts both arguments into a single line as
follows:


puts "#{ARGV[0]} #{ARGV[1]}"

I know this is simple (many things are missing) and that REALbasic can
concatenate, but! this is just a test. I dunno how REAL or RUBY are
gonna behave with a more complex example, but it's a beginning!!

I'll have to learn about sockets.

Advices? Comments?
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top