Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 10th, 2007, 10:28 PM
gcarcass gcarcass is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 4 gcarcass User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 9 sec
Reputation Power: 0
From REALbasic > Terminal > RUBY ?!

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, of course I would have to include the script file, but that's simpler no?)) 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:

Code:
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

Code:
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?

Reply With Quote
  #2  
Old May 11th, 2007, 08:38 AM
gcarcass gcarcass is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 4 gcarcass User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 9 sec
Reputation Power: 0
Finally!!!

This simple test is working as follow:

>>>> REAL CODE <<<<

Code:
  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:


>>>> RUBY CODE <<<<

Code:
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > From REALbasic > Terminal > RUBY ?!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway