Skip to content

Commit d9fba83

Browse files
authored
Merge pull request #61 from Anisimov-ds/master
Fix some bugs with pipe on Windows
2 parents 1825ebd + 65f67b3 commit d9fba83

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

testgres/node.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

testgres/utils.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import port_for
99
import subprocess
1010
import sys
11+
import tempfile
1112

1213
from contextlib import contextmanager
1314
from 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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy