@@ -230,6 +230,10 @@ def __init__(self, *args, **kw):
230230 self .register_backslash (r'\x' , self .bs_x ,
231231 "Execute the Python command within this process." )
232232
233+ def interact (self , * args , ** kw ):
234+ self .showhelp (None , None )
235+ super ().interact (* args ,** kw )
236+
233237 def register_backslash (self , bscmd , meth , doc ):
234238 self .bsc_map [bscmd ] = (meth , doc )
235239
@@ -308,7 +312,7 @@ def execfile(self, filepath):
308312 src .close ()
309313 if co is not None :
310314 try :
311- exec (co , self .globals , self .locals )
315+ exec (co , self .locals , self .locals )
312316 except :
313317 e , v , tb = sys .exc_info ()
314318 print_exception (e , v , tb .tb_next or tb )
@@ -330,7 +334,7 @@ def bs_E(self, cmd, arg):
330334 self .editfiles ([self .resolve_path (x ) for x in self .split (arg ) or ('' ,)])
331335
332336 def bs_e (self , cmd , arg ):
333- 'edit and execute the files'
337+ 'edit * and* execute the files'
334338 filepaths = [self .resolve_path (x ) for x in self .split (arg ) or ('' ,)]
335339 self .editfiles (filepaths )
336340 for x in filepaths :
@@ -341,7 +345,10 @@ def bs_x(self, cmd, arg):
341345 if len (cmd ) > 1 :
342346 a = self .split (arg )
343347 a .insert (0 , '\\ x' )
344- rv = command (args = a )
348+ try :
349+ rv = command (argv = a )
350+ except SystemExit as se :
351+ rv = se .code
345352 self .write ("[Return Value: %d]%s" % (rv , os .linesep ))
346353
347354 def push (self , line ):
@@ -591,8 +598,8 @@ def get_main_source(self):
591598 if path is not None :
592599 return loader .get_source (path )
593600
594- def command_execution (args = sys .argv ):
595- 'create an execution using the given args '
601+ def command_execution (argv = sys .argv ):
602+ 'create an execution using the given argv '
596603 # The pwd should be in the path for python commands.
597604 # setuptools' console_scripts appear to strip this out.
598605 if '' not in sys .path :
@@ -604,15 +611,15 @@ def command_execution(args = sys.argv):
604611 )
605612 op .disable_interspersed_args ()
606613 op .add_options (default_optparse_options )
607- co , ca = op .parse_args (args [1 :])
614+ co , ca = op .parse_args (argv [1 :])
608615
609616 return Execution (ca ,
610617 context = getattr (co , 'python_context' , ()),
611618 loader = getattr (co , 'python_main' , None ),
612619 )
613620
614- def command (args = sys .argv ):
615- return command_execution (args = args )(
621+ def command (argv = sys .argv ):
622+ return command_execution (argv = argv )(
616623 context = postmortem (os .environ .get ('PYTHON_POSTMORTEM' ))
617624 )
618625
0 commit comments