Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Query

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The concept behind it? Its a wildcard.
 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand a wild card works in ordinary circumstances but I am unable to relate it to JAVA.
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic