wildcards

R

Roedy Green

I just discovered something odd. EVERY Java utility has wildcard
ability on the command line.

If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?

if you write *.* as a parameter, you will get a list of all files and
directories in the current directory beginning with a.

But if you type . you just get the . This mechanism only seems to
kick in when you use a wildcard ? or *.

It is somewhat dangerous. *.* for a utility not prepared for it. *.*
does a directory 1-deep recursion.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
W

Wendy Smoak

Roedy Green said:
If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?

If you're doing at the command line, then I would bet the operating system
is evaluating the "*.*" before passing it as an argument to 'java'.
 
K

Kamal Chandana

It's nothing to do with java. It's solely due to the command line
behavior. The console interprets the *.* as - all the files in current
directory.

So the java program receives the list of all the file names in ur
directory.
 
P

Patricia Shanahan

Wendy said:
If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?


If you're doing at the command line, then I would bet the operating system
is evaluating the "*.*" before passing it as an argument to 'java'.

I'm sure Roedy is aware of command line expansion. In any case, I just
did some tests, and there is something else going on. For example, using
Cygwin's bash, the line:

echo '*'

echoes an asterisk, so single quotes suppress the expansion, as they
should in bash.

On the other hand, in the same shell:

java Echo '*'

gets a directory listing, where Echo is a program that prints its
arguments. So far, I have been unable to pass an asterisk
to my program, which seems unfortunate. If I decorate it enough to
prevent expansion, the decoration gets passed through as part of the
argument. For example '"*"' is passed as "*" (three characters).

I've checked the documentation for "java", and it does not describe this
behavior.

Patricia
 
S

shakah

Roedy said:
I just discovered something odd. EVERY Java utility has wildcard
ability on the command line.

If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?

if you write *.* as a parameter, you will get a list of all files and
directories in the current directory beginning with a.

But if you type . you just get the . This mechanism only seems to
kick in when you use a wildcard ? or *.

It is somewhat dangerous. *.* for a utility not prepared for it. *.*
does a directory 1-deep recursion.
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes

I'd think it is your command shell doing filename expansion, analogous
to Bash's globbing:
http://www.tldp.org/LDP/abs/html/globbingref.html
 
S

shakah

Patricia said:
Wendy said:
If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?


If you're doing at the command line, then I would bet the operating system
is evaluating the "*.*" before passing it as an argument to 'java'.

I'm sure Roedy is aware of command line expansion. In any case, I just
did some tests, and there is something else going on. For example, using
Cygwin's bash, the line:

echo '*'

echoes an asterisk, so single quotes suppress the expansion, as they
should in bash.

On the other hand, in the same shell:

java Echo '*'

gets a directory listing, where Echo is a program that prints its
arguments. So far, I have been unable to pass an asterisk
to my program, which seems unfortunate. If I decorate it enough to
prevent expansion, the decoration gets passed through as part of the
argument. For example '"*"' is passed as "*" (three characters).

I've checked the documentation for "java", and it does not describe this
behavior.

Patricia

For what it's worth I don't see the behavior you describe with Bash
under Linux:

jc@sarah:~/tmp$ echo $BASH_VERSION
3.00.14(1)-release

jc@sarah:~/tmp$ cat Echo.java
public class Echo {
public static void main(String [] asArgs) {
for(int nArg=0; nArg<asArgs.length; ++nArg) {
System.out.println(nArg + ". '" + asArgs[nArg] + "'") ;
}
}
}

jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/java Echo '*'
0. '*'

jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/java Echo \*
0. '*'

jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/java Echo "\*"
0. '\*'

jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/java Echo *
0. 'abstract-test'
1. 'aide-0.10'
2. 'audacity-src-1.2.3'
3. 'axis-1_2'
etc.
 
S

SMC

Wendy said:
If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?


If you're doing at the command line, then I would bet the operating
system is evaluating the "*.*" before passing it as an argument to
'java'.
I'm sure Roedy is aware of command line expansion. In any case, I just
did some tests, and there is something else going on. For example, using
Cygwin's bash, the line:

echo '*'

echoes an asterisk, so single quotes suppress the expansion, as they
should in bash.

On the other hand, in the same shell:

java Echo '*'

gets a directory listing, where Echo is a program that prints its
arguments. So far, I have been unable to pass an asterisk to my program,
which seems unfortunate. If I decorate it enough to prevent expansion,
the decoration gets passed through as part of the argument. For example
'"*"' is passed as "*" (three characters).

I've checked the documentation for "java", and it does not describe this
behavior.

Patricia

[sean@se2 tmp]$ cat e.java
public class e {

public static void main (String args[]){
System.out.println(args[0]);
}
}
[sean@se2 tmp]$ java e \*
*
[sean@se2 tmp]$ java e \*.\*
*.*
 
K

Kamal Chandana

In widows console u can send * to the java program using "*".

public class ArgsPrinter{

public static void main(String args[]){

System.out.println("Number of Arguments: " + args.length);

for(int i=0;i<args.length; i++){
System.out.println(args);
}
}

}

Just try to run the program as;

run ArgsPrinter "*"

result:
Number of Arguments: 1
*

- So you can input *.
 
?

.

I just discovered something odd. EVERY Java utility has wildcard
ability on the command line.

If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?

if you write *.* as a parameter, you will get a list of all files and
directories in the current directory beginning with a.

But if you type . you just get the . This mechanism only seems to
kick in when you use a wildcard ? or *.

It is somewhat dangerous. *.* for a utility not prepared for it. *.*
does a directory 1-deep recursion.

It is Windows that is doing it. I believe since 5.0 (Windows 2000) the
command line will expand the wildcards * and ? before passing to a
program.
 
H

Harald

Patricia Shanahan said:
I'm sure Roedy is aware of command line expansion. In any case, I just
did some tests, and there is something else going on. For example, using
Cygwin's bash, the line:

echo '*'

echoes an asterisk, so single quotes suppress the expansion, as they
should in bash.

On the other hand, in the same shell:

java Echo '*'

gets a directory listing, where Echo is a program that prints its

Is the program called `java' under cygwin a wrapper script which gets
its argument passing to the real program all messed up?

Harald.
 
P

Patricia Shanahan

Harald said:
Is the program called `java' under cygwin a wrapper script which gets
its argument passing to the real program all messed up?

Good question, but it doesn't seem to be:

[510] which java
/cygdrive/c/Program Files/Java/jdk1.5.0/bin/java

/cygdrive/c is the unix-like path Cygwin gives to C:, so that is
C:/Program Files/Java/jdk1.5.0/bin/java, my JDK1.5 java.exe.

I also tested, before posting, with 1.4 by forcing the java.exe file
name, and it behaved the same way.

Patricia
 
R

Roedy Green

I'm sure Roedy is aware of command line expansion.

I wasn't until I did some experiments. I wrote a little essay, as
usual on what I found out about command line expansion.

see http://mindprod.com/jgloss/wildcard.html

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Raymond DeCampo

Patricia said:
Wendy said:
If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?



If you're doing at the command line, then I would bet the operating
system is evaluating the "*.*" before passing it as an argument to
'java'.

I'm sure Roedy is aware of command line expansion. In any case, I just
did some tests, and there is something else going on. For example, using
Cygwin's bash, the line:

echo '*'

echoes an asterisk, so single quotes suppress the expansion, as they
should in bash.

On the other hand, in the same shell:

java Echo '*'

gets a directory listing, where Echo is a program that prints its
arguments. So far, I have been unable to pass an asterisk
to my program, which seems unfortunate. If I decorate it enough to
prevent expansion, the decoration gets passed through as part of the
argument. For example '"*"' is passed as "*" (three characters).

I've checked the documentation for "java", and it does not describe this
behavior.

This has to due with the way wildcard expansion is handled in Windows.
Wildcard expansion is not handled by the command interpreter, as in Unix
shells. Wildcard expansion is built into the console application (those
of you familiar with Visual C++ will know t=what the settings are to do
this).

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/basic_22.asp>

HTH,
Ray
 
R

Raymond DeCampo

Roedy said:
I wasn't until I did some experiments. I wrote a little essay, as
usual on what I found out about command line expansion.

see http://mindprod.com/jgloss/wildcard.html

Roedy,

Portions of the essay are somewhat misleading. In Windows, it is not
the command interpreter or BAT language that expands the wildcards. It
is the application that is invoked that does the expanding. This
explains why wildcard expansion in Windows can be inconsistent from
program to program.

I am confused by one part of your essay:

- Oddly if you pass a wild card to any Java utility, the command
- processor expands the wildcards so that you program for *.* will see
- list of all the directories and all the files, one per arg slot.

Unless the directories have the a period character in the name, they
should not match the *.* wildcard expression. If this does happen
perhaps you have found a bug in the JVM.

HTH,
Ray
 
R

Raymond DeCampo

.. said:
I just discovered something odd. EVERY Java utility has wildcard
ability on the command line.

If you write *.* as a parameter, you don't see "*.*" appearing in
args[0]. Instead you see a list of all the filenames and directory
names in the current directory, one per argument.

Is this new? Who is doing this? Windows, 4NT, Java?

if you write *.* as a parameter, you will get a list of all files and
directories in the current directory beginning with a.

But if you type . you just get the . This mechanism only seems to
kick in when you use a wildcard ? or *.

It is somewhat dangerous. *.* for a utility not prepared for it. *.*
does a directory 1-deep recursion.


It is Windows that is doing it. I believe since 5.0 (Windows 2000) the
command line will expand the wildcards * and ? before passing to a
program.

I posted the following link as evidence that it is not the command
interpreter but the application that expands wildcards:

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/basic_22.asp>

If this did indeed change in Windows 2000, I would like to read some
documentation on that. Can you provide a link?

(While it is true that I do not think this is the case, my request is
genuine.)

Thanks,
Ray
 
H

Hemal Pandya

It seems to have something to do with bash, but I wonder what. The
results are different on Windows command interpreter and on cygwin
bash:

C:\java>java Echo *
0. 'ant'
1. 'Echo.class'
2. 'Echo.java'
3. 'Echo.java~'
4. 'game'
5. 'test'

C:\java>java Echo '*'
0. ''*''

C:\java>java Echo "*"
0. '*'
 
C

Chris Uppal

shakah said:
For what it's worth I don't see the behavior you describe with Bash
under Linux:

That is because the java program on Unix does not do command-line expansion.
It -- correctly -- expects the invoking command processor to do whatever
expansion is required.

Under Windows (as under DOS) the architecture is different (and /very/ stupid,
IMO): individual commands are expected to do their own expansion. That means
that the Windows version of the java program is expanding the wildcard
according to whatever rules are compiled into it, and there is nothing that the
command processor (the cygwin version of bash in Patricia's example) can do
about it.

Command-line processing under Windows is, and always has been, utterly broken.

-- chris
 
C

Chris Head

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

Raymond said:
Roedy said:
I wasn't until I did some experiments. I wrote a little essay, as
usual on what I found out about command line expansion.

see http://mindprod.com/jgloss/wildcard.html

Roedy,

Portions of the essay are somewhat misleading. In Windows, it is not
the command interpreter or BAT language that expands the wildcards. It
is the application that is invoked that does the expanding. This
explains why wildcard expansion in Windows can be inconsistent from
program to program.

I am confused by one part of your essay:

- Oddly if you pass a wild card to any Java utility, the command
- processor expands the wildcards so that you program for *.* will see
- list of all the directories and all the files, one per arg slot.

Unless the directories have the a period character in the name, they
should not match the *.* wildcard expression. If this does happen
perhaps you have found a bug in the JVM.

HTH,
Ray


Hi,
At least in old DOS, *.* actually meant every file, whether or not it
contained a dot. This would be because every file "implicitly" had a dot
in it. Meanwhile, just asking for * I think didn't match anything.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFCvEVEgxSrXuMbw1YRAqgOAJ9eM8K+glgPCHUPWdlFwqnTYbevKgCdGKxQ
mHFmKixZIIIKyIldPd1pX+s=
=wex0
-----END PGP SIGNATURE-----
 
R

Roedy Green

Portions of the essay are somewhat misleading. In Windows, it is not
the command interpreter or BAT language that expands the wildcards. It
is the application that is invoked that does the expanding. This
explains why wildcard expansion in Windows can be inconsistent from
program to program.

I am confused by one part of your essay:

- Oddly if you pass a wild card to any Java utility, the command
- processor expands the wildcards so that you program for *.* will see
- list of all the directories and all the files, one per arg slot.

Unless the directories have the a period character in the name, they
should not match the *.* wildcard expression. If this does happen
perhaps you have found a bug in the JVM.


try this out. I think you will be surprised.

/**
* Tests what sort of wildcard expansion happens automatically.
* It is very simple. Just look at the main method code to understand
* what it does and what you could use it for.
*
* try with:
* java WildcardExpansion *.*
* java WildcardExpansion "*.*"
* java WildcardExpansion s*.*
* java WildcardExpansion .
* java WildcardExpansion *.html
* java WildcardExpansion afile.txt anotherfile.txt
* java WildcardExpansion d?mmy.* (where you have dummy.* files and a
dummy dir)
* java WildcardExpansion t?mmy.* (where you don't have tummy.* files
or a tummy dir)
*
* My discoveries: For Win2K:
* Wildcards are automatically expanded before your program sees them.
* Who does it? Presumably the command processor or a Sun class.
* You get a list of matching files INCLUDING matching directory
names,
* but not the files in those subdirectories. Since directories
normally
* don't have extensions, you won't see the problem with *.html but
you will
* with s*.* or *.*.
* If the wildcard does not match anything, you get the raw wildcard.
* The wildcard in quotes gives you the raw wildcard.
* Author Roedy Green
* Version 1.0
*/

public class WildcardExpansion
{
/**
* Echo command line arguments, along with any automatic expansion
* Can be used to test wildcard expansion, quoting, or any other
basic features
* features of command line parsing.
*
* @param args whatever you want to test.
*/
public static void main ( String[] args )
{
System.out.println ( args.length + " arguments" );

for ( int i=0; i<args.length; i++ )
{
// [ ] help prove no lead/trail blanks tabs etc.
System.out.println( "[" + args + "]" );
}
}
}

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green


So this implies the JRE is calling setargv or equivalent for you. In
other words, the screw up is Sun's fault, not Microsofts that you
can't tell a wildcard expansion asking for ONLY *.* files, from a list
of directories and files to process keyed out longhand.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ColorChooser for AWT 3
ConcurrentModificationException, please help 3
two jnlp questions 1
Splitting a class 5
java.jdk and java.jre system properties 5
extending enum 18
change log comments 1
sleep or beep 10

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top