windows - Calling cmd and passing arguments with Python subprocess -
i trying command run within python otherwise works fine bat file or in cmd command prompt.
python version 2.7.9.
the following works fine in command prompt:
"c:\program files (x86)\common files\aquatic informatics\aquarius\runreport.exe" -report="nhc_chart_1week_1series" -timeseries="precip total.24hr@fk intake forecast" -server="aqserver-van" -username="admin" -password="admin" -label="battery voltage data" -outputfile="c:\aquarius\reports\altagas\summary\24hr_precip_forecast.pdf" this calls program (runreport.exe) , passes bunch of arguments it. if things go file created.
it seems should able same in python subprocess.call have tried many different versions of code none of them run program correctly. below current code:
import subprocess run_report_program_path=r'c:\program files (x86)\common files\aquatic informatics\aquarius\runreport.exe' reportname="-report=nhc_chart_1week_1series" timeseries="-timeseries=precip total.24hr@fk intake forecast" server="-server=aqserver-van" user="-username=admin" passwrd="-password=admin" output="-outputfile=c:\aquarius\reports\altagas\summary\24hr_precip_forecast.pdf" result=subprocess.check_output([run_report_program_path, reportname, timeseries, server, user, passwrd, output], shell= true) the program runreport's 'pop up' runs quick , doesn't output desired result, instead error below. see issue?
traceback (most recent call last): file "c:\aquarius\scripts\api_import_and_trigger_reports_py\python_scripts\call_run_reports\test2.py", line 10, in <module> result=subprocess.check_output([run_report_program_path, reportname, timeseries, server, user, passwrd, output], shell= true) file "c:\python27\lib\subprocess.py", line 573, in check_output raise calledprocesserror(retcode, cmd, output=output) calledprocesserror: command '['c:\\program files (x86)\\common files\\aquatic informatics\\aquarius\\runreport.exe', '-report=nhc_chart_1week_1series', '-timeseries=precip total.24hr@fk intake forecast', '-server=aqserver-van', '-username=admin', '-password=admin', '-outputfile=c:\\aquarius\\reports\\altagas\\summary\x14hr_precip_forecast.pdf']' returned non-zero exit status 1 also, in command prompt returns nice set of errors (like time series not found, or report created successfully), don't these. possible these returned within python session?
subprocess.check_output raises exception if program not return zero. try insert r before output string, maybe why program fails.
also passes output return value, not see output if program passed.
Comments
Post a Comment