Command Line Quotiing Problem

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I wrote a litte program to explore what happens to interfere with characters on the command line passed to a progam. The source code is available at
http://mindprod.com/jgloss/commandline.html

Here are some puzzling results:

[C:\]java com.mindprod.example.TestParms "a b"
1 parameter
{a b}
--done--

[C:\]java com.mindprod.example.TestParms " \" "
1 parameter
{ " }
--done--

[C:\]java com.mindprod.example.TestParms " > "
1 parameter
{ > }
--done--

[C:\]java com.mindprod.example.TestParms " \" > "
TCC: (Sys) The system cannot find the file specified.

The puzzles:
1. the use of \" is not documented
2. > is sometimes treated literally and sometimes treated as redirection.

How do you quote a complex parm like a REGEX that may contain the kitchen sink " \ < > $? ; ` ? | &

I am using TCC 9.02.151 Windows Vista [Version 6.0.6001]
 
#2
On Sun, 08 Jun 2008 22:38:57 -0500, you wrote:


>C:\]java com.mindprod.example.TestParms " \" > "
>TCC: (Sys) The system cannot find the file specified.
>
>The puzzles:
>1. the use of \" is not documented
>2. > is sometimes treated literally and sometimes treated as redirection.
The trouble here is that while \ escapes the " as far as Java is concerned, it
doesn't in TCC. In the example above, TCC sends " \" to the program and tries
to set up redirection (which fails). I can overcome the difficulty (with a "C"
test program) like this.

v:\> u:\EchoArgs.exe `" \" > "`
u:\EchoArgs.exe (argv[0])
" > (argv[1], which has a trailing space)

Strong quotes (`) protect everything from TCC (except the action of TCC's escape
character (^)) and are not passed to the app. So for example (again with "C")

v:\> u:\EchoArgs.exe `" > < \" ^` | ^^"`
u:\EchoArgs.exe
> < " ` | ^ (all one arg)
--
- Vince