tags:

views:

75

answers:

4

I have a very simple question and I've even searched here but it's for a much simpler case than what I found examples of. I have a java program which has a simple System.in on the main function....I simply want to make a bat file which will run the java program and then enter the input stream automatically.

What I basicly want is this made by a batch file so I can make a test bench:

java Proj
module array1{}

And I wanted to run more modules as they are my tests.

Thanks in advance

A: 

I don't know if it is possible to do that with System.in, but have you considered in the alternative to just pass those as command line arguments to your main method?

Yishai
A: 

Okay, I'm not sure what precisely you're asking. Is there any reason you can't simply pass-in the parameters you need via the command line?

For instance, let's say you have a class MyJavaClass with a main method. You call it like this:

java MyJavaClass module1 module2 ... modulen

... and then assuming your main method looks like this:

public static void main (String[] args) {

... your args array will look like {"module1", "module2", ... "modulen"}, which you can then process and use for opening input streams as you see fit.

Or am I missing the point completely?

And if you're looking to create test code, have you taken a look at JUnit yet? No sense re-inventing the wheel unless you absolutely have to.

BlairHippo
+2  A: 

If I understand correctly, what you want is to run java Projand then write module array1{} or some other inputs to standard input.

If this is correct, you can put your input in a text file, say input.in and the just type in your bat file the following:

java Proj < input.in

I don't have a windows environment here to check it but I'm pretty sure that it'll work.

Santi P.
That's exactly what I wanted...for the last 2 hours.Thx alot
out_sider
You're welcome. BTW, you could make it simpler if you don't want to have an extra file, by using something like this: `echo "module array1{}" > java Proj`This works for sure in Unix. However, I'm not sure if the echo command is available in Windows, but surely there is some equivalent command that will help you spare the extra file.
Santi P.
A: 

Look into junit. It was designed for running test suites.

Thorbjørn Ravn Andersen