This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query" Watch "Query" New topic
Author

Query

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Hi

When we use * as a command line argument , the operating system supplies
all the names in the current working directory as the program's arguments?
What is the concept behind it?

Thanks
Regards
M.Kartik
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The concept behind it? Its a wildcard.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
I understand a wild card works in ordinary circumstances but I am unable to relate it to JAVA.
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
Originally posted by Kartik Mahadevan:
When we use * as a command line argument , the operating system supplies
all the names in the current working directory as the program's arguments?


that depends on the operating system.

Microsoft DOS/Windows (command.com, cmd.exe) does not, as far as i know, but the programs thus invoked are expected to interpret wildcards thusly themselves.

Linux/Unix command-line shells (bash, tcsh, ksh, and so on) expand wildcards before launching the program in question, replacing them with their expansion when invoking the program. the programs need not do this task, then -- but then again, the shells are replaceable, and there are several to choose from; so one could debate whether this is really an operating system function. at least in theory, one could have a Unix-like OS without a command-line shell, although i will admit it would be difficult.

What is the concept behind it?


i'm unsure what you mean to ask by this. the reason for doing wildcard expansion ("globbing") at the command line is to make the command line easier for humans to use.
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
I tested this program

class asdd {
public static void main( string args[])
{
for(int i=0;i<=args.length ; i++)
{
system.out.println(args[i]);
}
}
Now whenever I run this program at the command prompt C:> java asdd *
I get all the files in that operating system
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
This has nothing to do with Java at all. The operating system sees the command line string "java asdd *" and has to parse it in order to decide that Java even needs to be run. At that time, the OS sees the * and replaces it with the file names in the current working directory. This all happens before the JVM or your program even start. If you need to send a literal * as a command-line argument, you MUST quote (or escape it). This can be done in two ways:

java asdd \*

or

java asdd "*"

HTH

Layne


Java API Documentation
The Java Tutorial
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
I saw this very same example in book called 330 java tips but it didnt work on my system, win XP



kind regards
Igor
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Igor,

What do you mean by "it didn't work"? If you would like us to help you figure out how to make it work, you need to provide more details. Did you get it to compile? If not, what errors did you get? If so, did it run and how did the output differ from what you expected?

I'm not sure if you were making an aside comment or if you are asking for help, so please clarify.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query
 
Similar Threads
Runtime.getRuntime() help plzzzzzzzz
WA #1.....word association
Exception Requirements - "zero argument constructor" ?
Books on how to win an argument
setting system property in RAD