1

Possible Duplicate:
Java command line arguments. Using * as an argument for multiplication

i just wanted to write a simple calculator. If i enter 2 * 3 as parameters the array will look like this afterwards:

[2, .classpath, .project, .settings, bin, src, 3]

This happens for all our Eclipse installs in the company "Version: Indigo Service Release 2 Build id: 20120216-1857"

A friend of mine doesnt have this problem, so does anyone know the root of this problem?

greetings

Nico

Community
  • 1
  • 1
Nico Müller
  • 1,784
  • 1
  • 17
  • 37
  • 1
    Looks like the command shell (like bash) expands your arguments to file names. That would be a problem outside of your code or Java. How are you running your program? – Thilo Jun 04 '12 at 07:52
  • Thats true, i didnt find that post i am very sorry. – Nico Müller Jun 04 '12 at 08:05

3 Answers3

3

The parameter * gets replaced by the shell interpreter with the list of files in the current working directory. This typically happens on Linux/Unix platforms, but not (necessarily) on Windows. Does your friend use a Windows machine?

In other words, this has nothing to do with Java, but with the shell command interpreter which interprets your command line prior to executing java. To avoid it, you need to single-quote sensitive parameters, like java MyApp 2 '*' 3.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
0

You are passing the parameters on the command-line, where '*' is actually the wildcard character; it will match all files in the current directory (which happen to be .classpath, .project, .settings, bin, src.)

Miguel
  • 21
  • 1
0

If you're running under Unix, this is natural consequence of command-line expansion. Use \*, or "*". If you're on Windows, it doesn't happen.

Amadan
  • 191,408
  • 23
  • 240
  • 301