I want to execute the Java command: java -jar cli.jar <arg> <arg> from inside a PowerShell script. How do I pass the command line arguments passed to the PowerShell script to the Java command inside the script?
-
What is your question? How to write a powershell script that calls a java program? Or how that java program can react to the arguments provided to it?GhostCat– GhostCat2016-11-05 09:38:18 +00:00Commented Nov 5, 2016 at 9:38
-
1I think the question is how to convey the arguments passed by the caller of the script to the java program to be executed.Walter Mitty– Walter Mitty2016-11-05 12:43:57 +00:00Commented Nov 5, 2016 at 12:43
Add a comment
|
3 Answers
When you call your program like you did your application would receive three parameters, namely:
- dir
- -t
- i:\app
When you write your application you would normally write a main method that takes an arg array like this:
public static void main (String[] args)
{
// Code
}
To answer your question, the args array would now contain your three parameters. So if you would change your main method to:
public static void main (String[] args)
{
for (String arg : args) System.out.println(arg);
}
You would see your input parameters on the command line.