Run program with batch file
I know when using C++ you can do the following to read in a list of commands from a text file, run them against the program, and output the results to a text file:
ExampleProg < test.txt > results.txt
Can anyone tell me how to get the same result, but using a Java program. I do most programming in an IDE, so I'm not all that great with knowing what commands need to be done at the command line.
Is it something like the following?
java ExampleProg < test.txt > results.txt
Re: Run program with batch file
yeah, it is same thing
if you have JAR build you can use
java -jar your_file test.txt >> output.txt
or if you have compiled class files
java classfile.class test.txt >> output.txt
Java also uses main() function, there your arguments can be parsed.
1 Attachment(s)
Re: Run program with batch file
Quote:
Originally Posted by
postmortem
if you have JAR build you can use
java - jar your_file test.txt >> output.txt
When I try this method it says that it cannot create the java virtual machine. I've attached an image of what it tells me.
Batch file consists of: java - jar printStatement Input.txt >> output.txt
I'm not sure how the '1' that shows up after the input.txt in the image I attached gets in there.
Re: Run program with batch file
Code:
java -jar your_file test.txt >> output.txt
sorry, there is no space between '-' and 'jar'. make sure you follow rest of whitespaces. printStatement has to be JAR file.
Re: Run program with batch file
If you use the -jar option make sure you don't forget the .jar extension (printStatement.jar in this case). Also use redirection for the input file (<Input.txt) unless you read the file name from the arguments list and open the file yourself. With redirection you just use System.in.