Skip to content

Commit 99240e0

Browse files
committed
Merge pull request #789 from carlohamalainen/master
Don't call subprocess.Popen twice when output == 'file'.
2 parents 4d14512 + 0c4f587 commit 99240e0

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

nipype/interfaces/base.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,12 +1109,26 @@ def run_command(runtime, output=None, timeout=0.01):
11091109
The returned runtime contains a merged stdout+stderr log with timestamps
11101110
"""
11111111
PIPE = subprocess.PIPE
1112-
proc = subprocess.Popen(runtime.cmdline,
1113-
stdout=PIPE,
1114-
stderr=PIPE,
1115-
shell=True,
1116-
cwd=runtime.cwd,
1117-
env=runtime.environ)
1112+
1113+
if output == 'file':
1114+
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
1115+
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
1116+
stderr = open(errfile, 'wt')
1117+
stdout = open(outfile, 'wt')
1118+
1119+
proc = subprocess.Popen(runtime.cmdline,
1120+
stdout=stdout,
1121+
stderr=stderr,
1122+
shell=True,
1123+
cwd=runtime.cwd,
1124+
env=runtime.environ)
1125+
else:
1126+
proc = subprocess.Popen(runtime.cmdline,
1127+
stdout=PIPE,
1128+
stderr=PIPE,
1129+
shell=True,
1130+
cwd=runtime.cwd,
1131+
env=runtime.environ)
11181132
result = {}
11191133
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
11201134
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
@@ -1154,14 +1168,6 @@ def _process(drain=0):
11541168
result['stderr'] = stderr.split('\n')
11551169
result['merged'] = ''
11561170
if output == 'file':
1157-
stderr = open(errfile, 'wt')
1158-
stdout = open(outfile, 'wt')
1159-
proc = subprocess.Popen(runtime.cmdline,
1160-
stdout=stdout,
1161-
stderr=stderr,
1162-
shell=True,
1163-
cwd=runtime.cwd,
1164-
env=runtime.environ)
11651171
ret_code = proc.wait()
11661172
stderr.flush()
11671173
stdout.flush()

0 commit comments

Comments
 (0)