Skip to content

Commit f8ca556

Browse files
committed
add stderr support
1 parent 68bfef3 commit f8ca556

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

cwltool/cwltest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
114114
if "output" in t:
115115
checkkeys = ["output"]
116116
else:
117-
checkkeys = ["args", "stdin", "stdout", "createfiles"]
117+
checkkeys = ["args", "stdin", "stderr", "stdout", "createfiles"]
118118

119119
for key in checkkeys:
120120
try:

cwltool/draft2tool.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def rm_pending_output_callback(output_callback, jobcachepending,
206206
j.builder = builder
207207
j.joborder = builder.job
208208
j.stdin = None
209+
j.stderr = None
209210
j.stdout = None
210211
j.successCodes = self.tool.get("successCodes")
211212
j.temporaryFailCodes = self.tool.get("temporaryFailCodes")
@@ -227,6 +228,11 @@ def rm_pending_output_callback(output_callback, jobcachepending,
227228
j.stdin = builder.do_eval(self.tool["stdin"])
228229
reffiles.add(j.stdin)
229230

231+
if self.tool.get("stderr"):
232+
j.stderr = builder.do_eval(self.tool["stderr"])
233+
if os.path.isabs(j.stderr) or ".." in j.stderr:
234+
raise validate.ValidationException("stderr must be a relative path")
235+
230236
if self.tool.get("stdout"):
231237
j.stdout = builder.do_eval(self.tool["stdout"])
232238
if os.path.isabs(j.stdout) or ".." in j.stdout:

cwltool/job.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(self): # type: () -> None
4444
self.builder = None # type: Builder
4545
self.joborder = None # type: Dict[str,str]
4646
self.stdin = None # type: str
47+
self.stderr = None # type: str
4748
self.stdout = None # type: str
4849
self.successCodes = None # type: Iterable[int]
4950
self.temporaryFailCodes = None # type: Iterable[int]
@@ -137,6 +138,7 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
137138
env[key] = value
138139

139140
stdin = None # type: Union[IO[Any],int]
141+
stderr = None # type: IO[Any]
140142
stdout = None # type: IO[Any]
141143

142144
scr, _ = get_feature(self, "ShellCommandRequirement")
@@ -146,12 +148,13 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
146148
else:
147149
shouldquote = needs_shell_quoting_re.search
148150

149-
_logger.info(u"[job %s] %s$ %s%s%s",
151+
_logger.info(u"[job %s] %s$ %s%s%s%s",
150152
self.name,
151153
self.outdir,
152154
" \\\n ".join([shellescape.quote(str(arg)) if shouldquote(str(arg)) else str(arg) for arg in (runtime + self.command_line)]),
153155
u' < %s' % (self.stdin) if self.stdin else '',
154-
u' > %s' % os.path.join(self.outdir, self.stdout) if self.stdout else '')
156+
u' > %s' % os.path.join(self.outdir, self.stdout) if self.stdout else '',
157+
u' \2> %s' % os.path.join(self.outdir, self.stderr) if self.stderr else '')
155158

156159
if dry_run:
157160
return (self.outdir, {})
@@ -178,6 +181,15 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
178181
else:
179182
stdin = subprocess.PIPE
180183

184+
if self.stderr:
185+
abserr = os.path.join(self.outdir, self.stderr)
186+
dnerr = os.path.dirname(abserr)
187+
if dnerr and not os.path.exists(dnerr):
188+
os.makedirs(dnerr)
189+
stderr = open(absout, "wb")
190+
else:
191+
stderr = sys.stderr
192+
181193
if self.stdout:
182194
absout = os.path.join(self.outdir, self.stdout)
183195
dn = os.path.dirname(absout)
@@ -191,6 +203,7 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
191203
shell=False,
192204
close_fds=True,
193205
stdin=stdin,
206+
stderr=stderr,
194207
stdout=stdout,
195208
env=env,
196209
cwd=self.outdir)
@@ -203,6 +216,9 @@ def run(self, dry_run=False, pull_image=True, rm_container=True,
203216
if isinstance(stdin, file):
204217
stdin.close()
205218

219+
if stderr is not sys.stderr:
220+
stderr.close()
221+
206222
if stdout is not sys.stderr:
207223
stdout.close()
208224

cwltool/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def output_callback(out, processStatus):
183183
a = {"args": job.command_line}
184184
if job.stdin:
185185
a["stdin"] = job.pathmapper.mapper(job.stdin)[1]
186+
if job.stderr:
187+
a["stderr"] = job.stderr
186188
if job.stdout:
187189
a["stdout"] = job.stdout
188190
if job.generatefiles:

0 commit comments

Comments
 (0)