为什么这个python脚本在从批处理文件执行时不运行?

2024-10-03 02:33:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我设置了一个批处理文件来运行一个ghostscript,该脚本创建一个.pdf输出,然后我想在后续的python脚本中使用它。批处理文件本身运行时不会出现问题,如下所示:

"%PROGRAMFILES%\gs\gs9.54.0\bin\gswin64c.exe" -dBATCH -dSAFER -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dAutoRotatePages=/PageByPage -r600 -sOutputFile=%~dp0\%result%.pdf -
^&
"%~dp0\test.py" %result%.pdf

批处理文件日志显示它执行所有命令。此外,除了记录它运行的日志之外什么也不做的伪python脚本也可以完美地工作。但是,当我用虚拟脚本替换我想要使用的脚本时,该文件并没有做它应该做的事情,尽管它在控制台上自己运行时运行得很好。python脚本如下所示:

import os
import sys
from rmapy.document import ZipDocument
from rmapy.api import Client
        
# sets up the current directory to be the same as the .py file
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# sets up the remarkable api
rm=Client()
rm.renew_token()

# finds the pdf
for arg in sys.argv[1:]:
    print(arg)
    rawDocument = ZipDocument(doc=arg)
    rawDocument.metadata["VissibleName"]
    rm.upload(rawDocument)

我非常感谢你能提供的任何帮助。我怀疑.py文件中有什么东西在通过批处理文件调用时会产生错误,但我不知道是什么


Tags: 文件thermfrompyimport脚本pdf