Skip to content

Commit 56bf729

Browse files
Don't call subprocess.Popen twice when output == 'file'.
This fixes the real issue behind #705
1 parent 6634223 commit 56bf729

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

nipype/interfaces/base.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,26 @@ def run_command(runtime, output=None, timeout=0.01):
13011301
The returned runtime contains a merged stdout+stderr log with timestamps
13021302
"""
13031303
PIPE = subprocess.PIPE
1304-
proc = subprocess.Popen(runtime.cmdline,
1305-
stdout=PIPE,
1306-
stderr=PIPE,
1307-
shell=True,
1308-
cwd=runtime.cwd,
1309-
env=runtime.environ)
1304+
1305+
if output == 'file':
1306+
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
1307+
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
1308+
stderr = open(errfile, 'wt')
1309+
stdout = open(outfile, 'wt')
1310+
1311+
proc = subprocess.Popen(runtime.cmdline,
1312+
stdout=stdout,
1313+
stderr=stderr,
1314+
shell=True,
1315+
cwd=runtime.cwd,
1316+
env=runtime.environ)
1317+
else:
1318+
proc = subprocess.Popen(runtime.cmdline,
1319+
stdout=PIPE,
1320+
stderr=PIPE,
1321+
shell=True,
1322+
cwd=runtime.cwd,
1323+
env=runtime.environ)
13101324
result = {}
13111325
if output == 'stream':
13121326
streams = [Stream('stdout', proc.stdout), Stream('stderr', proc.stderr)]
@@ -1344,16 +1358,6 @@ def _process(drain=0):
13441358
result['stderr'] = stderr.split('\n')
13451359
result['merged'] = ''
13461360
if output == 'file':
1347-
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
1348-
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
1349-
stderr = open(errfile, 'wt')
1350-
stdout = open(outfile, 'wt')
1351-
proc = subprocess.Popen(runtime.cmdline,
1352-
stdout=stdout,
1353-
stderr=stderr,
1354-
shell=True,
1355-
cwd=runtime.cwd,
1356-
env=runtime.environ)
13571361
ret_code = proc.wait()
13581362
stderr.flush()
13591363
stdout.flush()

0 commit comments

Comments
 (0)