• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Stop Java from automatically interpreting a passed String argument that looks like a Path wildcard?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a simple program that outputs the arguments you give to it:

If you run this program passing "C:\*" as an argument:
Instead of outputting a single String "C:\*" Java will automatically interpret that as a wildcard and will instead output the contents of your C:\ folder, so instead of the args String array containing only 1 element, it contains a separate element for each file in your C:\ folder.

Normally that would be a smart thing to do but I'm writing my own implementation of DIR, and a user will sometimes pass multiple paths, some as wildcards and some normally, like: "java com.company.Main C:\* C:\Users\John John", and if I have multiple wildcard expressions in the passed arguments I have no way differentiating between an actual path specified by the user and an argument that Java automatically interpreted from a wildcard. Is there any way to turn this off and just have all arguments always be Strings?
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jeffersonian wrote:Stop Java from automatically interpreting a passed String argument that looks like a Path wildcard?



Unfortunately, it is not the JVM that is processing the command line wildcards. The wildcards are processed by the shell prior to calling the JVM.

You will need to looking into the shell that you are using, and modify your command line accordingly.

Henry
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd have to teach your users to type something like...

C:\> java com.company.Main "C:\*" "C:\Path With Spaces" C:\Users\John John

...which probably won't go over very well.
 
John Jeffersonian
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Drats! Oh well. Thanks for the clarification.
 
knowledge is the difference between drudgery and strategic action -- tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic