this is a Linux machine and the following code does not result in any output, I am curious why. P.S. - I didn't read about tilde needing to be escaped but in any case escaped tilde with a backslash and javac pointed out the syntax error.
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Run {
public static void main(String args[]) throws IOException {
Process p = Runtime.getRuntime().exec("ls ~");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
That's because
~
is replaced with the path to your home directory by the shell. You aren't using the shell. Instead, it's like you ranls '~'
, which gives the error:In fact, you can see just that happen when you change
p.getInputStream()
top.getErrorStream()
, which makes your program output: