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 or cmd.exe depending on Win95 or WinNT with a /K flag.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact