The easiest way is to capture stdout and stderr and send them to DEVNULL
(I'm using espeak 4; echo 'bye'
as a test command; echo
prints to stdout and espeak
, well, speaks so will have output that 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 you can do is send everything to /dev/null
, if you're on a linux/unix machine
In [16]: p = subprocess.Popen("echo 'bye' > /dev/null 2>&1", shell=True).wait()
# note: this is bash. Works for me on zsh as well,
# but might not work for other variants of sh
# use command 2> /dev/null if you only want to redirect stderr.
Addendum: Wait, you're using a pipe, the first command is clearly outputting to stderr
For your script, if I were to do with linux commands alone, I'd write it this 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 is awesome for breaking up long lines