【问题标题】:Using rm in a makefile on Windows with MSYS在带有 MSYS 的 Windows 上的 makefile 中使用 rm
【发布时间】:2016-04-27 11:51:34
【问题描述】:

我的 makefile 中有以下代码,用于在 tex 文件编译成功后删除我不想保留的文件。

grep '^OUTPUT ' $*.fls \
    | sed -e 's/^OUTPUT //' \
    | grep -vx $@ \
    | xargs rm
rm $*.fls
rm -f $*.bbl $*.blg

成功生成pdf后出现以下错误。

rm: cannot remove `00_Master_Thesis.log': Permission denied
rm: cannot remove `00_Master_Thesis.nlo': Permission denied
rm: cannot remove `00_Master_Thesis.aux': Permission denied
rm: cannot remove `00_Master_Thesis.out': Permission denied
make.exe": *** [00_Master_Thesis.pdf] Error 123

我尝试添加几个命令来获得删除这些文件的权限,并检查了包含这些文件的文件夹的权限。我也尝试以管理员身份启动 cmd,但似乎没有任何帮助。

相同的 makefile 在我的 Ubuntu 系统上运行良好。 如何让 make 在 Windows 上也删除这些文件?

编辑:

问题似乎是,pdflatex.exe 在编写 pdf 后没有退出。我什至无法手动删除这些文件,因为根据 Windows 资源管理器,它们仍然在 pdflatex.exe 中打开。

在我杀死 pdflatex.exe 后,错误消息现在只显示:

rm: cannot remove `00_Master_Thesis.log': Permission denied
make.exe": *** [00_Master_Thesis.pdf] Error 123

现在除了日志文件之外,只有 *.log、*.bbl、*.blg、*.fls、*.ilg 和 *.nls 文件不会被删除。在 make 完成后,*.aux、*.out 和 *.nlo 文件将永远消失,这至少是朝着正确方向迈出的一步。 ^^

如何让 pdflatex.exe get 退出或释放文件,以便 rm 删除它们?

【问题讨论】:

  • 但是pdflatex 真的在运行吗?由于 ms-windows 使用文件锁定,这可能是pdflatex 退出时没有删除锁定的情况。
  • 根据任务管理器,是的,make完成后pdflatex.exe还在运行。
  • 如果您手动运行pdflatex,它会在完成后退出还是继续运行?将标准输入/输出/错误从/到/dev/null 在这里有帮助吗?
  • 你给pdflatex什么选项?我建议-interaction batchmode-halt-on-error
  • @RolandSmith 太棒了。我有-halt-on-error 选项,但没有-interaction batchmode。添加此选项可以解决问题! :)

标签: windows permissions makefile latex pdflatex


【解决方案1】:

按照@RonaldSmith 的建议,尝试添加两个选项:

-halt-on-error-interaction batchmode,

那么它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2023-01-02
    • 2014-03-27
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多