【发布时间】:2015-10-07 10:29:16
【问题描述】:
我面临的问题可能有一个简单的解决方案,但由于我不是 php 专家,所以我找不到它。当我必须从 php 调用 shell 命令时,我通常会这样做:
cmd = "convert file.pdf image.jpg";
shell_exec($cmd);
但是现在我有一个可以在 shell 上运行的命令,我无法让它从 php 运行,所以我认为可能有一种方法可以用 php 语言来表达相同的命令,
命令:
for i in $(seq --format=%3.f 0 $nf); do echo doing OCR on page $i; tesseract '$imgdir/$imgdir-$i.ppm' '$imgdir-$i' -l eng; done
我的 php 尝试:
<?php
$imgdir = "1987_3";
$nf = count(new GlobIterator('filesup/'.$imgdir.'/*'));
$cmd = "for i in $(seq --format=%3.f 0 $nf); do echo doing OCR on page $i; tesseract '$imgdir/$imgdir-$i.ppm' '$imgdir-$i' -l eng; done"
shell_exec($cmd);
?>
我得到的是:
PHP Notice: Undefined variable: i in count.php on line 7
非常欢迎提出建议...谢谢
更新
我已经从我被标记为可能重复的问题中阅读了这个问题,我从中了解到我的“i”必须有一个引用,对于 shell 命令,它有,但它确实从 php 执行时不起作用。
对此,我也试过这个不成功:
<?php
$imgdir = "1987_3";
$nf = count(new GlobIterator('filesup/'.$imgdir.'/*'));
$cmd ="seq --format=%3.f 0 $nf";
$i = shell_exec($cmd);
$cmd = "tesseract 'filesup/$imgdir/$imgdir-$i.jpg' 'filesup/$imgdir/$imgdir-$i' -l eng; done";
shell_exec($cmd);
?>
【问题讨论】: