python - Suppressing messages to terminal from spawned process -
this question has answer here:
i've got command looks this
subprocess.popen('shp2pgsql -s 17932 \\storage1\dev1\gis\a.shp asmithe.mytable | psql -u asmithe -h example.org -d inventory -q', shell=true).wait()
heinous know. outputs screen , don't want that. how can supress it? psql
has -q
option quiet can't find simillar shp2pgsql
the easiest way capture stdout , stderr , send them devnull
(i'm using espeak 4; echo 'bye'
test command; echo
prints stdout , espeak
, well, speaks have output isn't captured)
in [14]: p = subprocess.popen("espeak 4; echo 'bye'", shell=true, \ stdout=subprocess.devnull, stderr=subprocess.devnull).wait() in [15]: p = subprocess.popen("espeak 4; echo 'bye'", shell=true).wait() bye
the other thing can send /dev/null
, if you're on linux/unix machine
in [16]: p = subprocess.popen("echo 'bye' > /dev/null 2>&1", shell=true).wait() # note: bash. works me on zsh well, # might not work other variants of sh # use command 2> /dev/null if want redirect stderr.
addendum: wait, you're using pipe, first command outputting stderr
for script, if linux commands alone, i'd write way:
subprocess.popen('shp2pgsql -s 17932 \\storage1\dev1\gis\a.shp asmithe.mytable 2> /dev/null | ' 'psql -u asmithe -h example.org -d inventory -q', shell=true).wait() #implicit string concat awesome breaking long lines
Comments
Post a Comment