File tree 2 files changed +31
-9
lines changed
2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -865,8 +865,7 @@ def psql(self,
865
865
"-X" , # no .psqlrc
866
866
"-A" , # unaligned output
867
867
"-t" , # print rows only
868
- "-q" , # run quietly
869
- dbname
868
+ "-q" # run quietly
870
869
] # yapf: disable
871
870
872
871
# set variables before execution
@@ -881,6 +880,9 @@ def psql(self,
881
880
else :
882
881
raise QueryException ('Query or filename must be provided' )
883
882
883
+ # should be the last one
884
+ psql_params .append (dbname )
885
+
884
886
# start psql process
885
887
process = subprocess .Popen (
886
888
psql_params ,
Original file line number Diff line number Diff line change 8
8
import port_for
9
9
import subprocess
10
10
import sys
11
+ import tempfile
11
12
12
13
from contextlib import contextmanager
13
14
from distutils .version import LooseVersion
@@ -59,13 +60,32 @@ def execute_utility(args, logfile=None):
59
60
"""
60
61
61
62
# 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
69
89
out = '' if not out else out .decode ('utf-8' )
70
90
71
91
# format command
You can’t perform that action at this time.
0 commit comments