Python을 사용하여 LaTeX 문서를 작성하려고하지만 명령을 순서대로 실행하는 데 문제가 있습니다. LaTeX에 익숙한 사람들은 일반적으로 다음 명령을 실행하기 전에 완료해야하는 4 개의 명령을 실행해야한다는 것을 알게 될 것입니다. 파이썬에서 Python에서 순차적으로 명령을 실행하십시오.
pdflatex file
bibtex file
pdflatex file
pdflatex file
, 나는 그러므로 명령
commands = ['pdflatex','bibtex','pdflatex','pdflatex']
commands = [(element + ' ' + src_file) for element in commands]
를 정의하려면이 일을 해요하지만 문제는이를 실행 중입니다.
나는 this thread –에서 물건을 꺼내려고했습니다. 루프에서 os.system()
을 사용하면 map(call, commands)
또는 Popen
과 같은 문자열로 목록이 축소되고 &
–으로 구분 된 단일 문자열로 목록이 축소되지만 이전 명령이 완료 될 때까지 기다리지 않고 명령이 모두 별도의 프로세스로 실행되는 것처럼 보입니다.
레코드의 경우 Windows에 있지만 크로스 플랫폼 솔루션을 원합니다.
EDIT
문제는 src_file 변수 speciyfing 버그이었다; 그것은 ".tex"가 없어야합니다.
\documentclass{article}
\usepackage{natbib}
\begin{document}
This is a test \citep{Body2000}.
\bibliographystyle{plainnat}
\bibliography{refs}
\end{document}
refs.bib
@book{Body2000,
author={N.E. Body},
title={Introductory Widgets},
publisher={Widgets International},
year={2000}
}
당신이 [그 스레드에서 허용 대답을 (사용하는 경우 http://stackoverflow.com/questions/359347/execute-commands-sequentially- :
하지만 subprocess.call를 사용하여 생각은 최선의 선택 in-python/359506 # 359506)가 작동해야하는 [Popen.wait()] (http://docs.python.org/library/subprocess.html?highlight=subprocess#subprocess.Popen.wait)을 사용합니다. – crashmstr
나는 그것이 유망 해 보였다고 생각했지만 솔직히 말해서 코드 예제를 실제로 따르지는 않습니다. 2 개의 클래스는 간단한 작업을위한 많은 코드처럼 보입니다. – jkeirstead
[answer from utdemir] (http://stackoverflow.com/questions/7365319/run-commands-sequential-from-python/7365350#7365350)이 더 간단합니다. 그러나 호출은 Popen (...)과 거의 비슷하게 반환 된 객체에서 wait()를 호출합니다. – crashmstr