0

我在 Linux 上的 phantomJS 中有一个脚本,它呈现一个示例网站:

var page = require('webpage').create();
page.open('http://www.example.com', function () {
    page.render('test.pdf');
    console.log('pdf render finished')
    phantom.exit();
});

我从 python 调用它:

os.system('phantomjs test.js')

我想要的是让 Python 知道 pdf 渲染已经完成的方法;类似于“pdf 渲染完成”这一行的监听器,或者类似这些行的东西。像这样的回调/侦听器将如何构建以及如何实现?

4

2 回答 2

2

您可以像这样使用子流程模块:

returncode =  subprocess.call(["phantomjs", "test.js"])

if returncode == 0:
   print "Application successfull executed"
else:
   print "There was an Error"
于 2013-11-11T21:25:41.297 回答
1

os.system只返回进程返回码。如果您想与进程交互,包括读取它的 STDOUT,请使用popen。您可以在您的进程和 phantomjs 之间创建一个 PIPE,然后等待“pdf 渲染完成”。

于 2013-11-11T21:24:26.340 回答