I'm using the java Process
class to execute some batch files. I'm using the ProcessBuilder
to create the process and this part run fine. My problem is to deal with the pause
command in the batch file I'm running. The pause
command is currently hanging the execution of the batch, but I need the batch to finish, so that I can resume pending operations. Currently, I'm starting a batch with a code equivalent to this:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
public class BatchEnter {
public static void main(String[] args) throws Exception {
List<String> params = Arrays.asList(new String[]{"cmd", "/C", "C:/test/test.bat"});
ProcessBuilder builder = new ProcessBuilder(params);
builder.directory(new File("C:/test")).redirectErrorStream(true);
Process p = builder.start();
BufferedReader wr = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while((line = wr.readLine())!=null){
System.out.println(line);
}
p.waitFor();
}
}
I'm aware that we can use this "hack" to skip the pause
command from a batch file. But, my problem is I can't change any of the batch files I'm using and I can't add a batch file to call another batch like in the link provided.
I was wondering is there a way to specify to the process to skip the pause command?