xvfb-run
py.sh 経由で実行しようとしていますがsh.ErrorReturnCode_1
、結果の pdf が作成されていません。
小さなhtmlファイルを作成しました:
$ echo '<h1>Hello, World.</h1>' > test.html
次にxvfb_run
、Python で sh.py を介して実行しました。
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sh import xvfb_run
>>> xvfb_run('--server-num=1 --server-args="-screen 0, 1024x768x24" '
... '/usr/bin/wkhtmltopdf --ignore-load-errors', 'test.html', 'test.pdf')
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/mark/.virtualenvs/reports/local/lib/python2.7/site-packages/sh.py", line 726, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/home/mark/.virtualenvs/reports/local/lib/python2.7/site-packages/sh.py", line 291, in __init__
self.wait()
File "/home/mark/.virtualenvs/reports/local/lib/python2.7/site-packages/sh.py", line 295, in wait
self._handle_exit_code(self.process.wait())
File "/home/mark/.virtualenvs/reports/local/lib/python2.7/site-packages/sh.py", line 309, in _handle_exit_code
self.process.stderr
sh.ErrorReturnCode_1:
RAN: '/usr/bin/xvfb-run --server-num=1 --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf --ignore-load-errors test.html test.pdf'
STDOUT:
STDERR:
次に、シェルに戻って、何かが作成されていて、何も作成されていないかどうかを確認します。
$ ls -l
total 4
-rw-rw-r-- 1 mark mark 23 May 22 07:54 test.html
したがってxvfb-run
、上記のコマンドをコピーすると、正常に動作します。
$ /usr/bin/xvfb-run --server-num=1 --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf --ignore-load-errors test.html test.pdf
Loading page (1/2)
Printing pages (2/2)
Done
そして、私が作成しようとしていたPDFファイルがあります:
$ ls -l
total 12
-rw-rw-r-- 1 mark mark 23 May 22 07:54 test.html
-rw-rw-r-- 1 mark mark 7091 May 22 07:55 test.pdf
call
次に、標準ライブラリのメソッドを試しました:
>>> from subprocess import call
>>> call(['/usr/bin/xvfb-run', '--server-num=1', '--server-args="-screen 0, 1024x768x24"', '/usr/bin/wkhtmltopdf', '--ignore-load-errors', 'test.html', 'test.pdf'])
xvfb-run: error: Xvfb failed to start
1
次に、DISPLAY
環境変数が設定されていないと思いましたが、それにも満足していません。
>>> import os
>>> os.environ["DISPLAY"]=":99"
>>> call(['/usr/bin/xvfb-run', '--server-num=1', '--server-args="-screen 0, 1024x768x24"', '/usr/bin/wkhtmltopdf', '--ignore-load-errors', 'test.html', 'test.pdf'])
xvfb-run: error: Xvfb failed to start
1
>>> call(['/usr/bin/wkhtmltopdf', '--ignore-load-errors', 'test.html', 'test.pdf'])
wkhtmltopdf: cannot connect to X server :99
1
>>> os.environ["DISPLAY"]=":1"
>>> call(['/usr/bin/wkhtmltopdf', '--ignore-load-errors', 'test.html', 'test.pdf'])
wkhtmltopdf: cannot connect to X server :1
py.shcall
がそのコマンドを実行できなかった理由は何ですか? 私がここに欠けているものはありますか?