无法使用代码运行子进程,commond 在终端上工作 [英] Unable to run a subprocess with code, the commond works on terminal

查看:48
本文介绍了无法使用代码运行子进程,commond 在终端上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 LibreOffice.docx 文件生成一个 PDF.这是我的子进程命令:

I am generating a PDF from .docx file using LibreOffice. This is my sub-process command:

output = subprocess.call('libreoffice --headless --convert-to pdf:writer_pdf_Export' + out_folder + ' ' + input_docx + ' -env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}',shell=True) 

当我在终端上运行它时 PDF 生成正确,但是当我调用这个子进程时.它给出了 127 错误代码.

When I run this on terminal PDF is generating properly but when I call this sub-process. It gives 127 error code.

推荐答案

使用下面的代码你可以得到你想要的结果.

Using the below code you can get your expected result.

import subprocess

out_folder = '/var/www/html/SocketQueue'
input_docx='/home/dhamo/Downloads/CNGroup_estimates.docx'
subprocess.call(['libreoffice', '--headless', '--convert-to','pdf:writer_pdf_Export', '--outdir', out_folder, input_docx,
'-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}'])

这篇关于无法使用代码运行子进程,commond 在终端上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆