Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Strange behavior with '*' character as command line argument.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The strangest thing is happening with this program: It crashes whenever it is given a '*' as a command line argument. If we modify it to use 'x' instead for multiplication, there are no problems. WHAT IS GOING ON HERE!
 
Sheriff
Posts: 26957
84
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is this: you are running the code from a Windows command shell (the "command line" window). When Windows sees the * character at the command line it interprets that as a request for a list of all files in the directory, and passes that list to the application. That would not be anything like what your code was expecting.

If you insert some debugging code you should be able to confirm (or not) that guess.
 
Eric Mitchell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As it turns out, that is exactly what is happening. I wrote some code to print the strings held in argv and it was a long list of files. Thank you for your help.
 
lowercase baba
Posts: 13019
66
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may be able to escape the * on the command line:

\*

unless windows uses the other slash:

/*

Or possibly put either it (or the entire argument string) in quotes

perhaps less than ideal, but it just may work...

NOTE: This is not unique to a Windows shell. I'm sure Unix would do the exact same thing.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic