Can I use wildcards(like *) inside Runtime.exec() to execute grep command?

Sandip Chitale

You can use -

Process pr =
Runtime.getRuntime().exec("/bin/sh -c 'grep -l "string" *'"); 

This works (on most Unices and Linux) because the interpretation of wild cards is really done by the shell process. And above that is what you are doing by executing /bin/sh. For windows it will be command.com or cmd.exe depending on Win95 or WinNT with a /K flag.