This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable number method parameters determined by .ini file

 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to use ProcessBuilder to initiate installations of other programs, like Adobe Reader, by reading something in like an ini file which would contain data similar to the following format:

So then my program would read that in (I know how to tokenize everything), and pass that data into a ProcessBuilder object. I've found that putting all of those commands into one "command" when creating a ProcessBuilder object doesn't work. You have to separate each command line argument into a separate ProcessBuilder command (from my experience). Since that's the case, how can I write my program to determine the right number of arguments to pass in and then create that ProcessBuilder object on the fly with an unknown number of command line arguments (at compile-time)? In case anyone is wondering, the only idea I have for now is to have something like a template for creating ProcessBuilder objects that I call based on the number of arguments passed in (and possibly have a limit on the total number of arguments), then call the right method basically based on that number. Isn't there a cleaner solution?
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the ProcessBuilder has two constructors - one that takes a List<String> and one that takes String varargs. I think the problem you are having is related to the use of the varargs version of the constructor. Why not use the List<String> version?
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know what? That's a perfect solution! Thanks for the tip! I wonder why I didn't find out about that before... I better read the manual next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic