PHP shell_exec不一致

时间:2012-11-15 01:42:24

标签: php macos osx-mountain-lion

我正在尝试在PDF文件中搜索多个关键字。我有大约60个PDF和~8个关键词,并不喜欢~480个手动搜索。

我愿意接受其他建议(见下文),但目前我的方法是在OS X上使用mdfind,如下所示:

$finds = array();
foreach ($search as $term) {
    $result = "";
    $cleanResult = array();
    $shellQuery = "mdfind -onlyin \"$wd\" \"kind:pdf $term\"";
    echo "\n\n$shellQuery\n";
    $result = shell_exec($shellQuery);
    echo $result;
    $cleanResult = split("\n", $result);
    array_pop($cleanResult);
    $finds[$term] = $cleanResult;

    unset($result);
    unset($cleanResult);
}
print_r($finds);

但是,虽然这构建$shellQuery很好,但由于某种原因$result并不总是填充,即使命令有效(即如果我复制并粘贴$shellQuery的值进入终端窗口,它按预期工作。)

假设$search包含'foo','bar'和'joe',它可能会发现'foo'和'joe'很好,但是没有为'bar'返回任何内容。如果我从数组中删除'foo'和'joe'并只搜索'bar',它会发现'bar'很好。是否需要在通话之间休息一下?!

顺便提一下,我首选的方法是做一些事情:

find . -name "*.pdf*" -exec pdftotext {} - \; | grep -i -l "foo"

但是我无法在终端中使用它。我已经安装了http://www.bluem.net/en/mac/packages/(我很难编译东西,所以像这样的包=竖起大拇指!),但每次我尝试将它传递给grep(例如pdftotext myfile.pdf - | grep -i -l "foo")grep只返回{{1而且没有了。

0 个答案:

没有答案