This doesn't work,
Runtime.getRuntime().exec("stat /*");
nor this;
Runtime.getRuntime().exec(new String[] {"stat", "/*"})
Is there any way around it ?
Thanks,
This doesn't work,
Runtime.getRuntime().exec("stat /*");
nor this;
Runtime.getRuntime().exec(new String[] {"stat", "/*"})
Is there any way around it ?
Thanks,
The asterisk is expanded by the shell (this is called globbing). So you actually want to execute the /bin/sh
executable (most likely - substitute another shell here if required), and invoke stat /*
from that. e.g. execute:
/bin/sh -c "stat /*"
from your Java process. -c
specifies that /bin/sh executes whatever is in the string following the -c
.
Alternatively you could perform the /*
expansion yourself by finding all the files in the root directory in Java, and then pass those as args to stat
.
You could delegate the task to the shell, like Brian Agnew said, or use Java to list all the files and directory in / (through Apache IO, for example), and replace /*
by the right list.
These answers didn't work so I created a shell file in which i wrote;
stat $1*
so whenever I need that asterisk to be added i call this file without it,
Runtime.getRuntime().exec("/my_shell_file /miki/");
it adds the asterisk for me and gives me back the output I need, as it runs:
stat /miki/*
Cheers,