@@ -314,22 +314,17 @@ def _execute(
314
314
raise WorkflowException (f"{ self .stdin } missing from pathmapper" )
315
315
else :
316
316
stdin_path = rmap [1 ]
317
-
318
- stderr_path = None
319
- if self .stderr is not None :
320
- abserr = os .path .join (self .base_path_logs , self .stderr )
321
- dnerr = os .path .dirname (abserr )
322
- if dnerr and not os .path .exists (dnerr ):
323
- os .makedirs (dnerr )
324
- stderr_path = abserr
325
-
326
- stdout_path = None
327
- if self .stdout is not None :
328
- absout = os .path .join (self .base_path_logs , self .stdout )
329
- dnout = os .path .dirname (absout )
330
- if dnout and not os .path .exists (dnout ):
331
- os .makedirs (dnout )
332
- stdout_path = absout
317
+ def stderr_stdout_log_path (base_path_logs , stderr_or_stdout ) -> Optional [str ]:
318
+ if stderr_or_stdout is not None :
319
+ abserr = os .path .join (base_path_logs , stderr_or_stdout )
320
+ dnerr = os .path .dirname (abserr )
321
+ if dnerr and not os .path .exists (dnerr ):
322
+ os .makedirs (dnerr )
323
+ return abserr
324
+ return None
325
+
326
+ stderr_path = stderr_stdout_log_path (self .base_path_logs , self .stderr )
327
+ stdout_path = stderr_stdout_log_path (self .base_path_logs , self .stdout )
333
328
commands = [str (x ) for x in runtime + self .command_line ]
334
329
if runtimeContext .secret_store is not None :
335
330
commands = cast (
@@ -395,6 +390,15 @@ def _execute(
395
390
"'listing' in self.generatefiles but no "
396
391
"generatemapper was setup."
397
392
)
393
+ # Move logs from log location to final output
394
+ if self .outdir != self .base_path_logs :
395
+ if stdout_path :
396
+ new_stdout_path = stdout_path .replace (self .base_path_logs , self .outdir )
397
+ shutil .copy2 (stdout_path , new_stdout_path )
398
+ if stderr_path :
399
+ new_stderr_path = stderr_path .replace (self .base_path_logs , self .outdir )
400
+ shutil .copy2 (stderr_path , new_stderr_path )
401
+
398
402
399
403
outputs = self .collect_outputs (self .outdir , rcode )
400
404
outputs = bytes2str_in_dicts (outputs ) # type: ignore
0 commit comments