簡體   English   中英

子進程調用python腳本不生成Jasper報告,但cmd執行

[英]Subprocess call python script not producing Jasper Report but cmd execution does

當我在命令行上運行它時,它會正確生成我的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中輸入命令時是否存在最大行長?

\\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"""

UPDATE

請嘗試以下操作:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM