我想向现有的子流程添加一个新的子流程。
我不想同时执行这两个进程,我只想将新的子进程(qpdf:假设将 pdfjam 的输出 pdf 线性化)添加到现有的子进程(pdfjam:将几个 pdf 一起添加),s。下面的代码,但是新添加的子进程并没有被执行,只有现有的一个。
我怎样才能解决这个问题?
这是代码的相关部分:
tmp_pdf_file = tmpdir + "/" + basename + ".pdf"
if os.path.exists(tmp_pdf_file):
subprocess.call(["pdfjam", "--keepinfo", "--noautoscale", "true", "--frame", "true", tmp_pdf_file, "-o", target_file_a4], cwd=tmpdir) # existing subprocess
self.progress.step()
subprocess.call(["qpdf", "--linearize", target_file_a4, target_file_a4], cwd=tmpdir) # new subprocess
self.progress.step()
shutil.move(tmp_pdf_file, target_file)
else:
print("No pdf file generated!")
编辑:我认为第二个子流程很难找到target_file_a4
,即使没有错误消息。
Edit2:communicate
代码运行没有任何错误消息(由于我的python技能很少,我不太确定我是否能够实施建议)。我检查输出 pdf 是否被线性化pdfinfo foobar.pdf
,这给了我Optimized: no
= 线性化:否,请参阅手册页。
编辑3:输出是:Extract init b"----\n pdfjam: This is pdfjam version 2.08.\n pdfjam: Reading any site-wide or user-specific defaults...\n (none found)\n pdfjam: Effective call for this run of pdfjam:\n /usr/bin/pdfjam --keepinfo --noautoscale 'true' --frame 'true' --outfile /path/to/foobar.pdf -- /tmp/extract-5j70hk9o/foobar.pdf - \n pdfjam: Calling pdfinfo...\n pdfjam: Calling pdflatex...\n pdfjam: Finished. Output was to '/path/to/foobar.pdf'.\n" b'/path/to/foobar.pdf (object 579 0, file position 7769200): EOF while reading token\n'
我可能会补充一点,我使用的是 python 3.5.0。
编辑4:
我今天早上做了我的研究,不得不评论说我已经将 cmidi 的代码片段添加到两个子进程中,添加到一个子进程和一个子进程pdfjam
中qpdf
。当我只使用第一个子流程执行此操作时,我收到的消息与在Edit3中发布的消息相同,但没有该b'/path/to/foobar.pdf (object 579 0, file position 7769200): EOF while reading token\n'
行。
Pdfjam
工作正常(因为输出 pdf 是一个完整的;pdflatex
创建几个单独的)。它显然与qpdf
,见这里。