Forums Register Login
Asterisk as a command-line argument
While goofing around writing a Java program that happens to sometimes take an asterisk (to indicate multiplication) as a command-line argument, I noticed some flaky behavior: I could only get the program to accept an asterisk if I put it in quotes.
Turns out, the command shell in Windows 2000 is expanding the * in the argument list to a list of files in the working directory before invoking java.exe.
Run this short program with the following arguments to see the effect:
java ArgPrinter someArg * anotherArg
java ArgPrinter someArg "*" anotherArg

Crazy, no?
I'm curious if folks on operating systems other than Windows run into this same sort of effect.
[ March 09, 2002: Message edited by: Michael Matola ]
Most shells have some notion of wild-card matching. This occurs under Unix as well. It's part of the command shell interpreter.
I guess what was tripping me up was the idea that the expansion of the wildcard must be happening before the interpreter even knows what program/command it's invoking.
These are my program's arguments after all, not something the operating system should care about!
The arguments belong to the command interpreter. It gets first dibs, and decides what information it feels like passing along to whatever program
This problem has reared its ugly head for me. I'm running Windows XP, and whether I use the asterisk in quotes or as just a plain old asterisk for my argument, it behaves as Michael experienced on Windows 2000 while not in quotes.
Anybody know of some escape character sequence to be able to pass the asterisk as an argument to a Java program?
In Unix we use "hard" quotes (single quote marks) to escape shell interpretation. Maybe try that on Windoze?
Well, leave it to Windows to provide an inconsistent and seemingly unexplainable experience. Since my original report, I've reinstalled Windows XP (from the same installation CD) and I now experience different results. Enclosing the asterisk in double quotes successfully passes only the asterisk character as a String parameter. Enclosing the asterisk in either of the single quotes - ' or ` - passes a String argument composed of the asterisk surrounded by the single quote characters. Go figure.
I promise I will be the best, most loyal friend ever! All for this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

This thread has been viewed 3289 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 17, 2019 13:30:26.