@@ -1583,6 +1583,42 @@ def quit():
15831583 self ._in_py = False
15841584 return self ._should_quit
15851585
1586+ # noinspection PyUnusedLocal
1587+ @options ([], arg_desc = '<script_path> [script_arguments]' )
1588+ def do_pyscript (self , arg , opts = None ):
1589+ """\n Runs a python script file inside the console
1590+
1591+ Console commands can be executed inside this script with cmd("your command")
1592+ However, you cannot run nested "py" or "pyscript" commands from within this script
1593+ Paths or arguments that contain spaces must be enclosed in quotes
1594+ """
1595+ if not arg :
1596+ self .perror ("pyscript command requires at least 1 argument ..." , traceback_war = False )
1597+ self .do_help ('pyscript' )
1598+ return
1599+
1600+ if not USE_ARG_LIST :
1601+ arg = shlex .split (arg , posix = POSIX_SHLEX )
1602+
1603+ # Get the absolute path of the script
1604+ script_path = os .path .abspath (os .path .expanduser (arg [0 ]))
1605+
1606+ # Save current command line arguments
1607+ orig_args = sys .argv
1608+
1609+ # Overwrite sys.argv to allow the script to take command line arguments
1610+ sys .argv = [script_path ]
1611+ sys .argv .extend (arg [1 :])
1612+
1613+ # Run the script
1614+ self .do_py ("run('{}')" .format (arg [0 ]))
1615+
1616+ # Restore command line arguments to original state
1617+ sys .argv = orig_args
1618+
1619+ # Enable tab completion of paths for pyscript command
1620+ complete_pyscript = path_complete
1621+
15861622 # Only include the do_ipy() method if IPython is available on the system
15871623 if ipython_available :
15881624 # noinspection PyMethodMayBeStatic,PyUnusedLocal
0 commit comments