Why is this Java code getting stuck?
I made a new process, but it never ends. I tried with ProcessBuilder and Runtime but neither worked, both stuck.
Builder code:
ProcessBuilder a = new ProcessBuilder(
"java",
"-classpath",
"D:\\TAP",
"AnalizadorLexico",
"<",
"D:\\TAP\\Lol1.txt");
Process process=a.start();
Runtime code:
Process process=cmd.exec(
"java -classpath D:\\TAP AnalizadorLexico < D:\\TAP\\Lol1.txt ");
The command works in Windows CMD.
+3
source to share
1 answer
From comments:
" <
" works with cmd (or other shells). Java program does not interpret it as input. You can use " cmd /c java progr < input
", but that makes it Windows specific.
The best way would be to use real Java APIs for it: see ProcessBuilder
Once you get past this check another FAQ on this
0
source to share