This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Variable number method parameters determined by .ini file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Variable number method parameters determined by .ini file" Watch "Variable number method parameters determined by .ini file" New topic
Author

Variable number method parameters determined by .ini file

Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
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?


Studying for SCJP 6
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4168
    
  21

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?


Steve
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable number method parameters determined by .ini file
 
Similar Threads
Is it possible to run a .msi file using Java's ProcessBuilder?
input data for external program
Threads and Databases
string diff
Execute command line command with arguments within Web Application