@@ -449,26 +449,13 @@ def run(self, updatehash=False):
449449 savepkl (op .join (outdir , '_node.pklz' ), self )
450450 savepkl (op .join (outdir , '_inputs.pklz' ), self .inputs .get_traitsfree ())
451451
452- try :
453- cwd = os .getcwd ()
454- except OSError :
455- # Changing back to cwd is probably not necessary
456- # but this makes sure there's somewhere to change to.
457- cwd = op .split (outdir )[0 ]
458- logger .warning (
459- 'Current folder "%s" does not exist, changing to "%s" instead.' ,
460- os .getenv ('PWD' , 'unknown' ), cwd )
461-
462- os .chdir (outdir )
463452 try :
464453 result = self ._run_interface (execute = True )
465454 except Exception :
466455 logger .warning ('[Node] Error on "%s" (%s)' , self .fullname , outdir )
467456 # Tear-up after error
468457 os .remove (hashfile_unfinished )
469458 raise
470- finally : # Ensure we come back to the original CWD
471- os .chdir (cwd )
472459
473460 # Tear-up after success
474461 shutil .move (hashfile_unfinished , hashfile )
@@ -586,17 +573,18 @@ def _run_command(self, execute, copyfiles=True):
586573 logger .info ("[Node] Cached - collecting precomputed outputs" )
587574 return result
588575
576+ outdir = self .output_dir ()
589577 # Run command: either execute is true or load_results failed.
590- runtime = Bunch (
591- returncode = 1 ,
592- environ = dict (os .environ ),
593- hostname = socket .gethostname ())
594578 result = InterfaceResult (
595579 interface = self ._interface .__class__ ,
596- runtime = runtime ,
580+ runtime = Bunch (
581+ cwd = outdir ,
582+ returncode = 1 ,
583+ environ = dict (os .environ ),
584+ hostname = socket .gethostname ()
585+ ),
597586 inputs = self ._interface .inputs .get_traitsfree ())
598587
599- outdir = self .output_dir ()
600588 if copyfiles :
601589 self ._originputs = deepcopy (self ._interface .inputs )
602590 self ._copyfiles_to_wd (execute = execute )
@@ -618,7 +606,7 @@ def _run_command(self, execute, copyfiles=True):
618606 message += ', a CommandLine Interface with command:\n {}' .format (cmd )
619607 logger .info (message )
620608 try :
621- result = self ._interface .run ()
609+ result = self ._interface .run (cwd = outdir )
622610 except Exception as msg :
623611 result .runtime .stderr = '%s\n \n %s' .format (
624612 getattr (result .runtime , 'stderr' , '' ), msg )
0 commit comments