From: Brian Candler Date: 2010-09-28T02:57:30+09:00 Subject: Re: passing single backslash character as commang line argument Kashyap Ivaturi wrote:0 > Please let me know how to get the backslash character in the string in > the test2.rb program. That depends. If you insist on invoking system with a single string argument, it gets passed to the shell to execute - something like /bin/sh -c "the string". This means the shell breaks it into words, and you have to deal with the shell's rules for handling quoting and backslashes: irb(main):004:0> str = "\\" # one backslash => "\\" irb(main):005:0> system("echo \"#{str}\"") sh: Syntax error: Unterminated quoted string => false irb(main):006:0> str = "\\\\" # two backslahses => "\\\\" irb(main):007:0> system("echo \"#{str}\"") \ => true If instead you use the multi-argument form of system, then you don't get a shell - Ruby invokes the program directly with the arguments given. This means you don't need to worry about backslashes, or even quoting. That is: system("/usr/bin/ruby", test2AbsolutePath, text) will pass those three args, and you don't need to quote the text even if it contains spaces, backslashes or whatever. I strongly recommend you go this way. To find the full path to the ruby interpreter, have a look at the rbconfig library. -- Posted via http://www.ruby-forum.com/.