Scripting with pipes and Java
I have a directory of folders, each containing a number of .class (Java) files. I would like to write a script to run each one and test it on a number of given inputs.
In otherwords, when I normally type "java myClass" in one of the folders, a console menu will appear and ask for some input. I might choose option "1" and hit enter; then it will ask me, say, what my name is - I'll type in my name, and it will bring the menu back up; and so on and so forth. I can probably figure out how to traverse all the folders (I just began scripting today), but I can't seem to figure out how to run the test cases on the java files. I tried scripts as simple as these: Code:
echo -e "1\nBlueRaja" | java myClass Code:
(echo 1; echo BlueRaja) | java myClass Code:
#!/bin/csh Thank you. |
The Java program reads input using the following code, if this helps:
Code:
InputStreamReader inStream = new InputStreamReader(System.in); |
hi,
try test.sh Code:
java myClass <<DELIMITER bye, mustafa |
both of these work:
Code:
echo 1 | java myClass Code:
java myClass <<DELIMITER Code:
java myClass <<DELIMITER |
Also: According to everything I've read, this should work:
Code:
input.txt: Code:
user% java myClass < input.txt |
The problem must be in your java code, I believe the first bufferedReader is flushed somewhere there.
A simple Java program using your sample code works fine under Unix: Code:
import java.io.*; |
Wait...I'm *not* supposed to flush the BufferedReader? o_O
Wow thanks, I think I can get it working now... but why does flushing BufferedReader screw it up? |
Because you discard the remaining lines before giving a chance your application to read them.
|
All times are GMT -5. The time now is 12:52 PM. |