我嘗試從腳本或cronjob啓動一個名爲ocrmypdf的python程序。無法通過sh/crontab啓動python程序
它完美地從終端,
[email protected]:~ $ ocrmypdf
usage: ocrmypdf [-h] [--verbose [VERBOSE]] [--version] [-L FILE] [-j N] [-n]
[--flowchart FILE] [-l LANGUAGE] [--title TITLE]
[--author AUTHOR] [--subject SUBJECT] [--keywords KEYWORDS]
[-d] [-c] [-i] [--oversample DPI] [-f] [-s]
[--skip-big MPixels] [--tesseract-config TESSERACT_CONFIG]
[--pdf-renderer {auto,tesseract,hocr}]
[--tesseract-timeout TESSERACT_TIMEOUT] [-k] [-g]
input_file output_file
ocrmypdf: error: the following arguments are required: input_file, output_file
但它打破的原因,我不明白另一個shell。
[email protected]:~ $ sh ocrmypdf
sh: 0: Can't open ocrmypdf
[email protected]:~ $ which ocrmypdf
/usr/local/bin/ocrmypdf
[email protected]:~ $ sh $(which ocrmypdf)
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
from: can't read /var/mail/ocrmypdf.main
/usr/local/bin/ocrmypdf: 10: /usr/local/bin/ocrmypdf: Syntax error: "(" unexpected (expecting "then")
這是執行的代碼:
[email protected]:~ $ cat $(which ocrmypdf)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from ocrmypdf.main import run_pipeline
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run_pipeline())
Cron作業無權訪問X11服務器。這是一個常見的常見問題。 – tripleee
這實際上不是問題。該程序不需要X11,我不知道爲什麼會出現此錯誤消息。 – bbk
啊,'import'命令需要X11,但你根本不想運行這個shell命令。 – tripleee