How can I do getRuntime (). exec with an asterisk?

This does not work,

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

and this;

 Runtime.getRuntime().exec(new String[] {"stat", "/*"}) 

Is there any way around this?

Thanks,

+4
source share
3 answers

These answers did not work, so I created a shell file in which I wrote;

 stat $1* 

so whenever I need this asterisk to add, I call this file without it,

 Runtime.getRuntime().exec("/my_shell_file /miki/"); 

it adds an asterisk for me and returns me the result that I need when it starts:

 stat /miki/* 

Greetings

0
source

The asterisk expands with a shell (this is called globalization). So you really want to execute the executable /bin/sh (most likely, replace another shell if necessary) and call stat /* from this. for example, execute:

 /bin/sh -c "stat /*" 

from your java process. -c indicates that / bin / sh does everything on the line following -c .

Alternatively, you can run the /* extension yourself, finding all the files in the root directory in Java, and then pass them as args to stat .

+8
source

You can delegate the task to the shell, as Brian Agnew said, or use Java to list all files and directories in / (via Apache IO , for example) and replace /* with the right list.

+1
source