How to paste or pipe input to a Java command line program?
March 10, 2009 11:59 AM
Subscribe
I have written a simple little Java program which runs on the command line, displays a text menu, and takes user input. I would like to feed it a very large amount of test input--as though an actual user were sitting there typing in commands all day. I am using Windows, but have access to the basic *nix utilities such as cat. "cat file.txt | java Program" doesn't work, nor does starting the program and using the context menu to paste in several lines of data.
The menu looks like this:
enter a value: e add: a
subtract: s multiply: m
reverse sign: r clear: c
quit: q
->
(only more formatted). After entering an option letter followed by the enter key, it prompts you for a value (value: ). I'd ultimately like to calculate 1000! as a test problem, so input would be like this:
e
1000
m
999
m
998
m
997
...
posted by anaelith to computers & internet (9 comments total)
Googling around, an example of someone doing something like this is here. You'll probably need to change your existing code so you can parameterize the input source, but maybe if you are using a kind of InputStream to read the user input, it won't be that hard.
posted by doteatop at 12:04 PM on March 10