Reputation: 61
So I need to make a java program that represents a bank tiller. However, I need to use an executable script that will feed the command line arguments to the java program. Unfortunately, there are multiple types of commands I can do that would need to call the java program.
Since there are different types of command options (start, buy, and change, I do not know how I could go about feeding the right argument information to the java program. Any assistance would be greatly appreciated.
Upvotes: 0
Views: 74
Reputation: 793
Take a look at the Apache CLI stuff. Specifically the POSIX parser (http://www.javaworld.com/article/2072482/command-line-parsing-with-apache-commons-cli.html)
It will enable you to specify POSIX style command line arguments (--buy {value} --sell {value})...
Upvotes: 0
Reputation: 201399
Unless I'm missing something, you could use $@
to pass the script's arguments to your Java program. For example,
#!/usr/bin/env bash
export CLASSPATH="$HOME/src/java/"
java com.example.MyTeller "$@"
Upvotes: 2
Reputation: 508
Here is a sample:
public class PrintArgs {
public static void main (String[] args) {
for (int x=0; x<args.length; x++) {
System.out.println(arg[x]);
}
}
}
Call it like this:
java PrintArgs start 80 = 10 2 2 2
The script I am not that sure about, but I you can look it up. Google shell scripts arguments.
Upvotes: 0
Reputation: 780673
Pass the script arguments to your Java program:
java programName "$@"
Upvotes: 1