When I run this at command line it generates my Jasper report correctly:
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
However, if I then try to run it through python with the following code the report doesn't get created. Am I messing up the syntax somewhere?
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)
EDIT:
Following the comments, I tried running this at cmd after typing python to bring up >>>:
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
This time I got a syntax error at -u. I then tried reordering the parameters and the syntax error then occurred at the same character number, rather than at the -u. So is there a maximum line length when entering commands in python at cmd?
\\a
is a escape sequence that is same to \\x07
(BEL). You should escape \\
or use raw string literal to make \\a
represent \\a
literally.
>>> '\a' # not escaped
'\x07'
>>> '\\a' # escaped
'\\a'
>>> r'\a' # raw string literal
'\\a'
So, replace following:
"""C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml"""
with
"""C:\\users\\ant\\jaspersoftworkspace\\myreports\\carereport.jrxml"""
or
r"""C:\users\ant\jaspersoftworkspace\myreports\carereport.jrxml"""
UPDATE
Try following:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.