I am writing program for tests automation purpose. That program would load list (names) of batch files from a folder program is in. Then I could select individual test or all and commence execution. Each batch file connects to the oracle, does some updates and more, and then selected output is spooled to a csv file and output file is placed to the local drive.
I wrote a program that loads batch file into the java program using ProcessBuilder, but when I tried to execute batch file it failed at opening sql script from bat file.
ProcessBuilder pb = new ProcessBuilder(System.getProperty("user.dir")+"//src//test.bat");
try {
pb.start();
Process process = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
System.out.println(sb);
bat file (very simple version):
@echo ON
set /A var = 100000000
sqlplus -s login/password@server @script.sql %var%
type results_*.csv > "results.csv"
del results_*.csv
When I'm debugging, the whole thing fails at opening sql script.
SP2-0310: can't open file "script.sql"
But I don't want bat file being opened and executed inside my program. I want my java program to launch windows command line that would execute my bat file. Is there any way to achieve this goal Or if there's no way - how could I parse that script file inside my program (I'd rather staw away from this path).