Building a Ruby executable that take a command-line argument

M

Max Power

So I've been using Ocra for awhile now to build my Ruby executables and
now I want to pass basically a flag to the executable and hopefully have
that argument be recognized within the ruby script itself. First off,
I'm not sure if this is even possible.

When I do run my .rb script by hand with an argument, it finds it and
all is well. When I take this command and try to build the executable,
it gives an error that the argument is nil (basically I do a simple puts
on the argument).

My hopeful end result will be to create one executable that will do
numerous tasks, all of which is driven by the argument sent in. My only
other option, as far as I know, would be to build separate executables
for these tasks; however, that would result in dozens of executables.

Thoughts/Suggestions?
 
L

Lars Christensen

So I've been using Ocra for awhile now to build my Ruby executables and
now I want to pass basically a flag to the executable and hopefully have
that argument be recognized within the ruby script itself. =A0First off,
I'm not sure if this is even possible.

When I do run my .rb script by hand with an argument, it finds it and
all is well. =A0When I take this command and try to build the executable,
it gives an error that the argument is nil (basically I do a simple puts
on the argument).

My hopeful end result will be to create one executable that will do
numerous tasks, all of which is driven by the argument sent in. =A0My onl= y
other option, as far as I know, would be to build separate executables
for these tasks; however, that would result in dozens of executables.

Thoughts/Suggestions?

Works for me.

C:\>type argv.rb
p ARGV

C:\>ocra argv.rb

C:\>argv.exe hello
["hello"]

Can you provide a minimal script showing the problem?

You can also ask questions specific for ocra here:
http://rubyforge.org/forum/forum.php?forum_id=3D31710
 
M

Max Power

Lars said:
My hopeful end result will be to create one executable that will do
numerous tasks, all of which is driven by the argument sent in. �My only
other option, as far as I know, would be to build separate executables
for these tasks; however, that would result in dozens of executables.

Thoughts/Suggestions?

Works for me.

C:\>type argv.rb
p ARGV

C:\>ocra argv.rb

C:\>argv.exe hello
["hello"]

Can you provide a minimal script showing the problem?

You can also ask questions specific for ocra here:
http://rubyforge.org/forum/forum.php?forum_id=31710

Thanks for the quick response. There were two issues on my end. (1)
When building the executable, I was actually building the executable as
such:

C:\>ocra argv.rb hello

The other things I was doing was attempting to concatenate a string to
the front end of the argument prior to outputting it

puts "ARGUMENT: "+ARGV[0]

So basically it works now and I'm an idiot :eek:)

Thanks again for the help!
 

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,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top