当我在命令行运行这个命令时,它正确地生成了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中的命令时,是否存在最大行长?
发布于 2014-03-16 00:47:48
\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)https://stackoverflow.com/questions/22431603
复制相似问题