简体   繁体   中英

find with escaped glob expansion works on command line; not in Java Runtime.exec

I'm running this command:

find /tmp/thumbnailgenerator/processor -maxdepth 1 -amin +1 -type f -iname 'a*' -delete

which works as expected when run from the command line. But when run as a singular command in Java via Runtime.getRuntime.exec(String command) , the files are not deleted. (Yes they are one minute old.) Also when run as a command array cmdarray that joins to the above string via StringUtils.join(cmdarray, ' ') , it still does not work.

I suspect this has to do with the glob expansion since I know a common mistake in using Runtime.exec is to assume it does glob expansion like bash does, but deleting * does not help (it still won't delete file a ).

This has to do with how the first round of processing is performed by bash v. exec, but not exactly glob expansion. Remove the ' ' around the filename and it should work. In bash, you use those quotes to prevent bash from expanding the glob. However single quote has no special meaning to exec either, so those are passed raw to the find command too. You want find to see a* . In bash, this means you must type 'a*' . But in exec, it means you must type a* or else find will see 'a*' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM