miktex (lualatex.exe) 无法从 flask 子进程 运行
miktex (lualatex.exe) fails to run from flask subprocess
我正在尝试使用 Flask 网络应用程序中的子进程调用构建乳胶文件。
def pdf(self, ixTestsheet):
build_dir = mkdtemp(prefix="testsheet_")
tsfile = NamedTemporaryFile(dir=build_dir, suffix=".tex", delete=False)
tsfile.write(self.latex(ixTestsheet, _print_type).encode("utf-8"))
old_dir = os.getcwd()
# os.chdir(build_dir)
latexname = os.path.basename(tsfile.name)
tsfile.close()
# added this to check user of subprocess
dirout = subprocess.run(
["whoami.exe"], cwd=build_dir, check=True, capture_output=True
)
current_app.logger.info(dirout)
try:
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
)
# call a second time to get a full build with page numbers etc.
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
)
except subprocess.CalledProcessError as e:
current_app.logger.error(build_dir)
current_app.logger.error(e)
如果我 运行 来自 Flask 应用程序的进程失败并出现以下错误。如果我 运行 来自交互式 python 会话的命令,它将完成。
[2020-12-04 11:51:13,512] INFO in testsheets: CompletedProcess(args=['whoami.exe'], returncode=0, stdout=b'<DOMAINNAME>\<USERNAME>\r\n', stderr=b'')
lualatex.exe: No suitable temporary directory found.
Sorry, but "c:/Program Files/MiKTeX 2.9/miktex/bin/x64/lualatex.exe" did not succeed.
FATAL: No suitable temporary directory found.
FATAL: Data:
FATAL: Source: Libraries\MiKTeX\Core\Session\miktex.cpp:79
[2020-12-04 11:51:13,745] ERROR in testsheets: C:\Users\USERNA~1\AppData\Local\Temp\testsheet_oreb8wg5
[2020-12-04 11:51:13,745] ERROR in testsheets: Command '['c:/Program Files/MiKTeX 2.9/miktex/bin/x64/lualatex.exe', '--interaction=nonstopmode', 'tmpfk6un0c7.tex']' returned non-zero exit status 1.
我想弄清楚为什么 MiKTeX 在 运行 来自 Flask 时无法找到临时目录,但在 运行 来自交互式会话时可以。
据我所知:
- 用户 运行 从 flask 应用程序中执行命令与用户 运行 从交互式会话中执行命令相同。
- MiKTeX 拥有构建 Latex 文件所需的所有包
- subprocess 命令不是问题
- 临时目录的权限似乎没问题
似乎 TMP
和 TEMP
都存在于 subprocess
环境中,但是 TMP
被设置为空字符串。 MiKTeX 在 TEMP
之前使用 TMP
所以它失败了。
这样解决了
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
env=dict(os.environ, TMP=os.environ["TEMP"]),
)
我正在尝试使用 Flask 网络应用程序中的子进程调用构建乳胶文件。
def pdf(self, ixTestsheet):
build_dir = mkdtemp(prefix="testsheet_")
tsfile = NamedTemporaryFile(dir=build_dir, suffix=".tex", delete=False)
tsfile.write(self.latex(ixTestsheet, _print_type).encode("utf-8"))
old_dir = os.getcwd()
# os.chdir(build_dir)
latexname = os.path.basename(tsfile.name)
tsfile.close()
# added this to check user of subprocess
dirout = subprocess.run(
["whoami.exe"], cwd=build_dir, check=True, capture_output=True
)
current_app.logger.info(dirout)
try:
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
)
# call a second time to get a full build with page numbers etc.
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
)
except subprocess.CalledProcessError as e:
current_app.logger.error(build_dir)
current_app.logger.error(e)
如果我 运行 来自 Flask 应用程序的进程失败并出现以下错误。如果我 运行 来自交互式 python 会话的命令,它将完成。
[2020-12-04 11:51:13,512] INFO in testsheets: CompletedProcess(args=['whoami.exe'], returncode=0, stdout=b'<DOMAINNAME>\<USERNAME>\r\n', stderr=b'')
lualatex.exe: No suitable temporary directory found.
Sorry, but "c:/Program Files/MiKTeX 2.9/miktex/bin/x64/lualatex.exe" did not succeed.
FATAL: No suitable temporary directory found.
FATAL: Data:
FATAL: Source: Libraries\MiKTeX\Core\Session\miktex.cpp:79
[2020-12-04 11:51:13,745] ERROR in testsheets: C:\Users\USERNA~1\AppData\Local\Temp\testsheet_oreb8wg5
[2020-12-04 11:51:13,745] ERROR in testsheets: Command '['c:/Program Files/MiKTeX 2.9/miktex/bin/x64/lualatex.exe', '--interaction=nonstopmode', 'tmpfk6un0c7.tex']' returned non-zero exit status 1.
我想弄清楚为什么 MiKTeX 在 运行 来自 Flask 时无法找到临时目录,但在 运行 来自交互式会话时可以。
据我所知:
- 用户 运行 从 flask 应用程序中执行命令与用户 运行 从交互式会话中执行命令相同。
- MiKTeX 拥有构建 Latex 文件所需的所有包
- subprocess 命令不是问题
- 临时目录的权限似乎没问题
似乎 TMP
和 TEMP
都存在于 subprocess
环境中,但是 TMP
被设置为空字符串。 MiKTeX 在 TEMP
之前使用 TMP
所以它失败了。
这样解决了
subprocess.run(
[
current_app.config["LUALATEX_EXE"],
"--interaction=nonstopmode",
latexname,
],
cwd=build_dir,
check=True,
env=dict(os.environ, TMP=os.environ["TEMP"]),
)