Reputation: 708
I have a Java Application project in Eclipse and the executable receives parameters. The application then outputs a result value in a file. I want to, after running with many different parameters, compare these results.
If I could do something like this, like in a command prompt, it would be perfect:
run MyProgram --a hi --b 200
run MyProgram --a hello --b 333
...
run MyProgram --a something --b 10000
How can I do this with the Eclipse IDE?
If I can't do it by the IDE means, what would be the best way to manually do it (like with a .bat file)?
Upvotes: -1
Views: 4087
Reputation: 8616
Better to use script to run your program several times with different parameters. Follow the below procedure to achieve this.
I have a java program which takes one input parameter. Below is the code
package org.stackoverflow;
public class Testing {
public static void main(String[] args) {
String inputString = args[0];
System.out.println("inputString:" + inputString);
}
}
I prepared one .bat file (TestingJavaProgramming.bat) to run this program again and again with different parameter and write the result into a .txt file after printing the result into console.
TestingJavaProgramming.bat file content
cd D:\All_POCs\WorkSpace\TestCoreJava\src
javac org\stackoverflow\Testing.java
java org.stackoverflow.Testing "This is 1st time testing">>result.txt
java org.stackoverflow.Testing "This is 2nd time testing">>result.txt
type result.txt
And the output after executing the batch file
D:\>TestingJavaProgramming.bat
D:\>cd D:\All_POCs\WorkSpace\TestCoreJava\src
D:\All_POCs\WorkSpace\TestCoreJava\src>javac org\stackoverflow\Testing.java
D:\All_POCs\WorkSpace\TestCoreJava\src>java org.stackoverflow.Testing "This is 1st time testing" 1>>result.txt
D:\All_POCs\WorkSpace\TestCoreJava\src>java org.stackoverflow.Testing "This is 2nd time testing" 1>>result.txt
D:\All_POCs\WorkSpace\TestCoreJava\src>type result.txt
inputString:This is 1st time testing
inputString:This is 2nd time testing
You can also see the output inside the result.txt file.Hope my hints will help you.
Upvotes: 0
Reputation: 176
Go to run configuration, Arguments tab -> in the program arguments text box -> type space separated values to send arguments.
If you want to dynamically pass values on every launch and don't wanna open run configuration, then click on variables button and choose string_prompt. And provide variable name as follows -
${string_prompt: varName1}
${string_prompt: varName2}.
So you will be popped up a dialog asking you to enter the input values.
Better approach would be to put all your input values in a txt file, read the input file line by line and run your logic and compare the results. This would make your life easier.
Hope this helps.
Upvotes: 0
Reputation: 917
Basically, it's simple. Click on Run -> Run Configurations Click on the Arguments tab. You want to type in all your input values into the Program arguments window, with spaces (blank characters) between each value. Then just click Apply, followed by Run.
Upvotes: 1