Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > quote stripping in windows ruby.exe command line

Reply
Thread Tools

quote stripping in windows ruby.exe command line

 
 
Timothy Byrd
Guest
Posts: n/a
 
      10-02-2005
Given this one-line Ruby script:

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

ruby.exe (1.8.2 on Windows)

[C:\] c:\ruby\bin\ruby.exe argvtest.rb "quoted"
ARGV[0] is quoted

Should ruby.exe be stripping the quotes? How can I pass in a string
with quotes?

-- Timothy

 
Reply With Quote
 
 
 
 
William James
Guest
Posts: n/a
 
      10-02-2005

Timothy Byrd wrote:
> Given this one-line Ruby script:
>
> puts "ARGV[0] is #{ARGV[0]}"
>
> ruby.exe (1.8.2 on Windows)
>
> [C:\] c:\ruby\bin\ruby.exe argvtest.rb "quoted"
> ARGV[0] is quoted
>
> Should ruby.exe be stripping the quotes? How can I pass in a string
> with quotes?
>
> -- Timothy


ruby.exe argvtest.rb '"quoted"'

ruby.exe argvtest.rb "\"quoted\""

 
Reply With Quote
 
 
 
 
Austin Ziegler
Guest
Posts: n/a
 
      10-02-2005
On 10/2/05, Timothy Byrd <(E-Mail Removed)> wrote:
> Given this one-line Ruby script:
>
> puts "ARGV[0] is #{ARGV[0]}"
>
> ruby.exe (1.8.2 on Windows)
>
> [C:\] c:\ruby\bin\ruby.exe argvtest.rb "quoted"
> ARGV[0] is quoted
>
> Should ruby.exe be stripping the quotes? How can I pass in a string
> with quotes?


This is not Ruby doing this.

-austin
--
Austin Ziegler * http://www.velocityreviews.com/forums/(E-Mail Removed)
* Alternate: (E-Mail Removed)


 
Reply With Quote
 
Timothy Byrd
Guest
Posts: n/a
 
      10-03-2005

[hoping this isn't a double post]

William James wrote:

> ruby.exe argvtest.rb '"quoted"'
>
> ruby.exe argvtest.rb "\"quoted\""


Thanks. I didn't get this at first because my shell uses a caret (^)
as the escape character, not the backslash - backslash being the
directory separator on the PC.

After reading your reply, I realized I needed to go through the code to
figure out how Ruby is really behaving. For example, the MSVC runtime
strips out all quotes not escaped by a backslash, so the first example
of '"quoted"' shouldn't have worked, yet it does.

It turns out that, under Windows, ruby.exe ignores argv and reparses it
from the raw command line. In rb_w32_cmdvector() in win32.c, the
section with the comment:

//
// if it's an input vector element and it's enclosed by quotes,
// we can remove them.
//

does just that.

This is important to me because of a project embedding Ruby, which
wasn't stripping quotes. I passed in a quoted filename and IO#foreach
failed. Yet the same script ran correctly with the same arguments when
called through ruby.exe.

Filenames under Windows cannon contain the double quote character, and
most of the Windows API functions work with filenames containing double
quotes by simply pretending they aren't there. (I'd say all the API
functions, but this *is* Windows, after all.) It would be nice if Ruby
under Windows was as tolerant.

Thanks again,

-- Timothy

 
Reply With Quote
 
Timothy Byrd
Guest
Posts: n/a
 
      10-03-2005
William James wrote:

> ruby.exe argvtest.rb '"quoted"'
>
> ruby.exe argvtest.rb "\"quoted\""


Thanks. I didn't get this at first because my shell uses a caret (^)
as the escape character, not the backslash - backslash being the
directory separator on the PC.

After reading your reply, I realized I needed to go through the code to
figure out how Ruby is really behaving. For example, the MSVC runtime
strips out all quotes not escaped by a backslash, so the first example
of '"quoted"' shouldn't have worked, yet it does.

It turns out that, under Windows, ruby.exe ignores argv and reparses it
from the raw command line. In rb_w32_cmdvector() in win32.c, the
section with the comment:

//
// if it's an input vector element and it's enclosed by quotes,
// we can remove them.
//

does just that.

This is important to me because of a project embedding Ruby, which
wasn't stripping quotes. I passed in a quoted filename and IO#foreach
failed. Yet the same script ran with the same arguments when called
through ruby.exe.

Filenames under Windows cannon contain the double quote character, and
most of the Windows API functions work with filenames containing double
quotes by simply pretending they aren't there. (I'd say all the API
functions, but this *is* Windows, after all.) It would be nice if Ruby
under Windows was as tolerant.

Thanks again,

-- Timothy

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem: neither urllib2.quote nor urllib.quote encode the unicodestrings arguments Valery Khamenya Python 3 10-05-2008 10:16 AM
Quote-Dot-Quote Operator kvnsmnsn@hotmail.com C++ 6 06-14-2008 11:34 PM
Datagrid on load; replace all double single quote to single quote to display to user Eric Layman ASP .Net 3 04-14-2007 07:16 AM
replacing strange quote with standard quote Stimp ASP .Net 2 09-20-2006 10:01 AM
Single Quote Versus Double Quote In A href link knee-dragger@hotmail.com HTML 3 06-13-2006 12:42 AM



Advertisments