【发布时间】:2021-08-25 13:47:41
【问题描述】:
我正在使用 subprocess 而不是 os.system 来执行 shell 命令以异步将文档转换为 pdf。重复调用时,大约 50% 的文件会失败。它不会将 doc 文件转换为 pdf。我该如何解决它。
conversion_process = await asyncio.create_subprocess_shell( 'soffice -env:UserInstallation=file:///tmp/LibreOffice_Conversion_' + author + ' --headless --convert-to pdf --outdir ' + folder + ' ' + input_file, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await conversion_process.communicate()
if stderr:
app.logger.error(f"stderr: {stderr}")
错误信息:
stderr: b'javaldx: Could not find a Java Runtime Environment!
Please ensure that a JVM and the package libreoffice-java-common
is installed.
If it is already installed then try removing ~/.config/libreoffice/4/user/config/javasettings_Linux_*.xml
Warning: failed to read path from javaldx
【问题讨论】:
-
能否分享一下失败的错误信息
-
@PouyaEsmaeili,我在上面的问题中添加了错误消息。
-
@PouyaEsmaeili,但我有一个疑问,如果上面提到的错误消息是原因,那么为什么其他命令执行成功。他们也应该抛出这个错误。
标签: python asynchronous async-await operating-system subprocess