简体   繁体   English

在命令行中找到带有转义的glob扩展的作品; 不在Java Runtime.exec中

[英]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. 但是,当通过Runtime.getRuntime.exec(String command)在Java中以单个命令运行时,不会删除文件。 (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. (是的,它们已经一分钟了。)同样,当作为通过StringUtils.join(cmdarray, ' ')连接到上述字符串的命令数组cmdarray运行时,它仍然不起作用。

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 ). 我怀疑这与glob扩展有关,因为我知道使用Runtime.exec犯的错误是假定它像bash一样进行glob扩展,但是删除*并没有帮助(它仍然不会删除文件a )。

This has to do with how the first round of processing is performed by bash v. exec, but not exactly glob expansion. 这与bash v.exec如何执行第一轮处理有关,而与glob扩展无关。 Remove the ' ' around the filename and it should work. 删除文件名周围的' ' ,它应该可以工作。 In bash, you use those quotes to prevent bash from expanding the glob. 在bash中,使用这些引号可以防止 bash扩展全局。 However single quote has no special meaning to exec either, so those are passed raw to the find command too. 但是,单引号对exec也没有特殊含义,因此它们也将原始传递给find命令。 You want find to see a* . 您想找到a* In bash, this means you must type 'a*' . 在bash中,这意味着您必须输入'a*' But in exec, it means you must type a* or else find will see 'a*' . 但是在exec中,这意味着您必须键入a* ,否则find将看到'a*'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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