Search code examples
javabashexecstat

stat returns `No such file or directory`, run under java exec


I want to call stat in Java, using:

Runtime.getRuntime().exec("stat /*")

But always get exit code -1 and:

stat: cannot stat `/*': No such file or directory

Run stat /* in bash is OK, and this is also OK:

Runtime.getRuntime().exec("stat /")

Has stat /* in Java a different behavior as in bash?


Solution

  • stat /* works in the command line because the shell interprets the *. You should try running through bash, e.g., bash -c stat /*