我目前用法是subprocess.call(sh, shell=True),用于调用某个程序,然后控制台就顺带把这程序运行过程中的各种输出都打印了出来:
/usr/local/anaconda2/bin/python /home/victi/VIC_Hime/test.py Mon, 17 Oct 2016 21:04:02 INFO Calibrating start. Mon, 17 Oct 2016 21:04:02 INFO Turns 1 Mon, 17 Oct 2016 21:04:02 INFO Calibrate infilt Exec shell: /home/victi/VIC/vic/build/vic_image -g /home/victi/TRMM_VIC/SC/global.txt global_param: wind_h : 10.0000 resolution : 0.0000 dt : 86400.0000 snow_dt : 86400.0000 runoff_dt : 86400.0000 model_steps_per_day : 1 snow_steps_per_day : 1 runoff_steps_per_day: 1 endday : 31 endmonth : 12 endyear : 2002 ...
从“global_param"开始往后都是。有何方法可让这些信息不显示?
三叔2016-10-22 17:46:32
>>> p = subprocess.Popen('pwd', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>> sout = p.stdout.readlines() >>> sout ['/root\n']