[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Need help in option parser

Kwong Goh

4/11/2008 11:05:00 PM

I am using optionparser to take in arguement. However, it seems like the
option parser does not accept "&" "|" "<" ">" as the arguement when they
are entered from the command line.

For example, I use opts.on("-d option"), when I enter -d 1&2 in the
command line, it will only accept 1 in this case.

May I know what is the reason for this and how to solve this problem?

Thanks.
--
Posted via http://www.ruby-....

3 Answers

Tim Hunter

4/11/2008 11:10:00 PM

0

Kwong Goh wrote:
> I am using optionparser to take in arguement. However, it seems like the
> option parser does not accept "&" "|" "<" ">" as the arguement when they
> are entered from the command line.
>
> For example, I use opts.on("-d option"), when I enter -d 1&2 in the
> command line, it will only accept 1 in this case.
>
> May I know what is the reason for this and how to solve this problem?
>
> Thanks.


Depends on what O/S and shell you're using. In most Linux shells those
characters are interpreted by the shell. In Windows both < and > are
interpreted by cmd.com. I don't know about the others.

You can make the shell ignore those characters by surrounding them with
quotes or escaping them with an acceptable escape character such as a
backslash.

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

RubyTalk@gmail.com

4/11/2008 11:11:00 PM

0

Try putting 1&2 in quotes "1&2". & | < > are used by the terminal.

Becker

On Fri, Apr 11, 2008 at 4:04 PM, Kwong Goh <kagohaik85@hotmail.com> wrote:
> I am using optionparser to take in arguement. However, it seems like the
> option parser does not accept "&" "|" "<" ">" as the arguement when they
> are entered from the command line.
>
> For example, I use opts.on("-d option"), when I enter -d 1&2 in the
> command line, it will only accept 1 in this case.
>
> May I know what is the reason for this and how to solve this problem?
>
> Thanks.
> --
> Posted via http://www.ruby-....
>
>

Phillip Gawlowski

4/11/2008 11:13:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kwong Goh wrote:
| I am using optionparser to take in arguement. However, it seems like the
| option parser does not accept "&" "|" "<" ">" as the arguement when they
| are entered from the command line.
|
| For example, I use opts.on("-d option"), when I enter -d 1&2 in the
| command line, it will only accept 1 in this case.
|
| May I know what is the reason for this and how to solve this problem?

Try to use a 'dir > text.txt', or 'ls > text.txt', or 'dmesg | grep a'
on the command line.

The symbols OptionPArse doesn't accept are reserved by the OS.

(| is the pipe in *NIX, && allows comamnd chaining in Windows and *NIX,
< and > are redirectors, which allow the use of a file as input to a
command, or direct the output of a command to a file, respectively.

There is no way *I* am aware of to circumvent these, except "Stop using
them". Maybe others know more.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

Make sure all variables are initialised before use.
~ - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail....

iEYEARECAAYFAkf/8JIACgkQbtAgaoJTgL9SbwCfZ0ZrK+fn5MdWAxtI9fxD1KdT
XTwAn3CfOlvi72aEwq8LUJEeSeEz2L0S
=fPwe
-----END PGP SIGNATURE-----