File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query

 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The concept behind it? Its a wildcard.
 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand a wild card works in ordinary circumstances but I am unable to relate it to JAVA.
 
M Beck
Ranch Hand
Posts: 323
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic