У меня есть скрипт Python, использующий pyhtml2pdf:
import os
import sys
from pyhtml2pdf import converter
def convert_html_to_pdf(html_path, pdf_path):
absolute_html_path = os.path.abspath(html_path)
converter.convert(f'file:///{absolute_html_path}', pdf_path, 60, False, 0, False)
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python3 test.py ")
else:
html_path = sys.argv[1]
pdf_path = sys.argv[2]
convert_html_to_pdf(html_path, pdf_path)
Когда я запускаю команду непосредственно на сервере Linux:
DISPLAY=:99 python3 test.py 298.html 298.pdf
он выполняется отлично, и создается файл 298.pdf. Однако когда я пытаюсь запустить эту команду из программы Java, используя:
String comds = "DISPLAY=:99 python3 test.py 298.html 298.pdf";
Runtime.getRuntime().exec(comds);
Я столкнулся с ошибкой:
2024-09-27 11:33:14 - ОШИБКА>Traceback (последний последний вызов):
р>
2024-09-27 11:33:14 - ERROR>Traceback (most recent call last):
2024-09-27 11:33:14 - ERROR> File "test.py", line 15, in
2024-09-27 11:33:14 - ERROR> convert_html_to_pdf(html_path, pdf_path)
2024-09-27 11:33:14 - ERROR> File "test.py", line 7, in convert_html_to_pdf
2024-09-27 11:33:14 - ERROR> converter.convert(f'file:///{absolute_html_path}', pdf_path, 20, False, 0, False)
2024-09-27 11:33:14 - ERROR> File "/usr/local/lib/python3.6/site-packages/pyhtml2pdf/converter.py", line 39, in convert
2024-09-27 11:33:14 - ERROR> source, timeout, install_driver, print_options)
2024-09-27 11:33:14 - ERROR> File "/usr/local/lib/python3.6/site-packages/pyhtml2pdf/converter.py", line 79, in __get_pdf_from_html
2024-09-27 11:33:14 - ERROR> driver = webdriver.Chrome(options=webdriver_options)
2024-09-27 11:33:14 - ERROR> File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
2024-09-27 11:33:14 - ERROR> self.service.start()
2024-09-27 11:33:14 - ERROR> File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
2024-09-27 11:33:14 - ERROR> self.assert_process_still_running()
2024-09-27 11:33:14 - ERROR> File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
2024-09-27 11:33:14 - ERROR> % (self.path, return_code)
2024-09-27 11:33:14 - ERROR>selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -11
2024-09-27 11:33:14 - ERROR>
Как решить эту проблему?
chromedriver -v
ChromeDriver 129.0.6668.70
Подробнее здесь: https://stackoverflow.com/questions/790 ... server-but