当我在命令行运行它时,它会正确生成我的Jasper报告:
jasperstarter pr "C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml" -f pdf -t postgres -H localhost -n template_postgis_20 -u postgres -p postgres -P SiteID=123
但是,如果我尝试使用以下代码通过python运行它,则不会创建报告。我在某处弄乱了语法吗?
import subprocess
from subprocess import call
subprocess.call(["cmd","/C","jasperstarter","pr","""C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml""","-f","pdf",
"-t","postgres","-H","localhost","-n","template_postgis_20","-u","postgres","-p","postgres",
"-P","SiteID=123"], shell=True)
修改
在评论之后,我尝试在输入python后在cmd运行此命令以显示>>>:
jasperstarter pr "C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml" -f pdf -t postgres -H localhost -n template_postgis_20 -u postgres -p postgres -P SiteID=123
这次我在-u遇到语法错误。然后我尝试重新排序参数,然后语法错误发生在相同的字符编号,而不是在-u。那么在cmd中在python中输入命令时是否有最大行长度?
答案 0 :(得分:1)
\a
是一个与\x07
(BEL)相同的转义序列。您应该转义\
或使用原始字符串文字使\a
字面上代表\a
。
>>> '\a' # not escaped
'\x07'
>>> '\\a' # escaped
'\\a'
>>> r'\a' # raw string literal
'\\a'
所以,请替换以下内容:
"""C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml"""
与
"""C:\\users\\ant\\jaspersoftworkspace\\myreports\\carereport.jrxml"""
或
r"""C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml"""
<强>更新强>
请尝试以下操作:
subprocess.call(r'jasperstarter pr "C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml" -f pdf -t postgres -H localhost -n template_postgis_20 -u postgres -p postgres -P SiteID=123', shell=True)