【问题标题】:why does subprocess fails during the given task?为什么子进程在给定任务期间失败?
【发布时间】: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


【解决方案1】:

您收到错误消息的原因是子流程使用并传递给 LibreOffice 的路径变量不足以找到 JRE。我遇到了同样的问题并将其更改为以下似乎可以解决的问题。

subprocess.run(cmd,env={'HOME':'/home/username'})

我同样可以确认,这个错误不会在每次调用时都发生,我对为什么会发生这种情况的猜测是 JRE 仅用于某些文档转换,而不是全部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 2020-01-21
    • 2011-03-12
    • 2011-07-12
    • 2012-11-17
    相关资源
    最近更新 更多