File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -865,8 +865,7 @@ def psql(self,
865865 "-X" , # no .psqlrc
866866 "-A" , # unaligned output
867867 "-t" , # print rows only
868- "-q" , # run quietly
869- dbname
868+ "-q" # run quietly
870869 ] # yapf: disable
871870
872871 # set variables before execution
@@ -881,6 +880,9 @@ def psql(self,
881880 else :
882881 raise QueryException ('Query or filename must be provided' )
883882
883+ # should be the last one
884+ psql_params .append (dbname )
885+
884886 # start psql process
885887 process = subprocess .Popen (
886888 psql_params ,
Original file line number Diff line number Diff line change 88import port_for
99import subprocess
1010import sys
11+ import tempfile
1112
1213from contextlib import contextmanager
1314from distutils .version import LooseVersion
@@ -59,13 +60,32 @@ def execute_utility(args, logfile=None):
5960 """
6061
6162 # run utility
62- process = subprocess .Popen (
63- args , # util + params
64- stdout = subprocess .PIPE ,
65- stderr = subprocess .STDOUT )
66-
67- # get result and decode it
68- out , _ = process .communicate ()
63+ if os .name == 'nt' :
64+ # using output to a temporary file in Windows
65+ buf = tempfile .NamedTemporaryFile ()
66+
67+ process = subprocess .Popen (
68+ args , # util + params
69+ stdout = buf ,
70+ stderr = subprocess .STDOUT
71+ )
72+ process .communicate ()
73+
74+ # get result
75+ buf .file .flush ()
76+ buf .file .seek (0 )
77+ out = buf .file .read ()
78+ buf .close ()
79+ else :
80+ process = subprocess .Popen (
81+ args , # util + params
82+ stdout = subprocess .PIPE ,
83+ stderr = subprocess .STDOUT )
84+
85+ # get result
86+ out , _ = process .communicate ()
87+
88+ # decode result
6989 out = '' if not out else out .decode ('utf-8' )
7090
7191 # format command
You can’t perform that action at this time.
0 commit comments