通过 exec() 调用的 PDFTK 无提示地失败

发布于 2024-10-02 16:28:56 字数 520 浏览 0 评论 0原文

我正在使用 pdftk 通过以下方式动态连接 pdf 文件像这样的 exec() 调用:

exec("/path/to/pdftk /path/to/file1.pdf /path/to/file2.pdf cat output path/to/output.pdf", $execoutput);

这一切在 Linux 环境中都运行得很好,但是当在我们的开发环境(Windows/Uniform Server 和 OSX/MAMP 的混合)上本地运行时,这似乎会默默地失败。 $execoutput 是一个空数组。

如果发送到 exec() 的命令被复制并粘贴到 Windows 或 OSX 中的命令行,它将具有所需的输出并生成串联文件。每台开发人员机器都安装了 pdftk,并且可以通过命令行证明其功能齐全。

目前这让我很困惑。我无法解释为什么会发生这种情况。

I'm using pdftk to concatenate pdf files on the fly by making an exec() call like so:

exec("/path/to/pdftk /path/to/file1.pdf /path/to/file2.pdf cat output path/to/output.pdf", $execoutput);

This all works perfectly well in a linux environment, but when run locally on our development environments (a mix of Windows/Uniform Server and OSX/MAMP) this seems to silently fail. $execoutput is an empty array.

If the command that is sent to exec() is copy and pasted to the command line in either Windows or OSX it has the desired output and the concatenated file is generated. Each developer machine has pdftk installed and it can be demonstrated to be fully functional from the command line.

This currently has me stumped. I am at a loss to explain why this is happening.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔日梦未散 2024-10-09 16:28:56

我终于明白发生了什么事。就像菜鸟一样,我假设每台机器都运行最新版本的 pdftk。他们不是。

看来上述问题与版本 1.43 中修复的已知错误有关

来自 http://www.pdflabs.com/docs/pdftk-version-history/

“清除信号掩码作为在调用 pdftk 之前关闭信号的环境的解决方法。已知此问题会导致 pdftk 在某些 Python Web 设置以及 PHP 中挂起。”

猜猜这是唯一运行版本 >= 1.43 的设置;-)

将每个开发环境更新到最新版本的 pdftk(当前为 1.44)已经解决了问题

I eventually figured out what was going on. Like a noob I had assumed every machine was running the latest version of pdftk. They weren't.

It would appear that the problem described above relates to a known bug which was fixed in version 1.43

From http://www.pdflabs.com/docs/pdftk-version-history/

"Clear the signal mask as workaround to environments that turn off signals before calling pdftk. This problem is known to cause pdftk to hang in some Python web setups as well as in PHP."

Guess which was the only setup to be running a version >= 1.43 ;-)

Updating each development environment to the latest version of pdftk (currently 1.44) has solved the problem

笑忘罢 2024-10-09 16:28:56

如果 pdftk 没有将输出添加到所需文件夹的权限,也可能会发生这种情况。如果打印 $execoutput (命令中带有“verbose”)并看到最后一个条目将是“Creating Output”,您可以看到这种情况发生。下一行应该说输出正在执行,但它只会在那里结束。这让我呆了一段时间(因为如果你直接在命令行上运行它就可以工作)。

This can also occur if pdftk does not have permission to the add the output to the desired folder. You can see this happening if you print out the $execoutput (with 'verbose' in the command) and see that the last entry will be 'Creating Output'. The next line should say that the output is being executed, but it will just end there. This got me for awhile (as it works if you run directly on the command line).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文