(self, command)
Run a SHELL subprocess.
Run a SHELL subprocess.
Run a SHELL subprocess .
def launch(self, command):
        """Run a SHELL subprocess."""
        logging.debug('Executing SHELL command `%r` with command interpreter `%s`', command, self._shell)
        if not self._shell:
            logging.warning('SHELL statement not enabled: no command interpreter specified.')
            raise error.BASICError(error.IFC)
        # split by whitespace but protect quotes
        cmd = split_quoted(self._shell, quote=u'"', strip_quotes=False)
        # find executable on path
        cmd[0] = which(cmd[0], path='.' + os.pathsep + os.environ.get("PATH"))
        if not cmd[0]:
            logging.warning(u'SHELL: command interpreter `%s` not found.', self._shell)
            raise error.BASICError(error.IFC)
        if command:
            cmd += [SHELL_COMMAND_SWITCH, self._codepage.bytes_to_unicode(command, box_protect=False)]
        # get working directory; also raises IFC if current_device is CAS1
        work_dir = self._files.get_native_cwd()
        try:
            p = Popen(
                cmd, shell=False, cwd=work_dir,
                stdin=PIPE, stdout=PIPE, stderr=PIPE,
                # first try with HIDE_WINDOW to avoid ugly command window popping up on windows
                startupinfo=HIDE_WINDOW
            )
        except EnvironmentError:
            try:
                # HIDE_WINDOW not allowed on Windows when called from console
                p = Popen(
                    cmd, shell=False, cwd=work_dir,
                    stdin=PIPE, stdout=PIPE, stderr=PIPE,
                )
            except EnvironmentError as err:
                logging.warning(
                    u'SHELL: command interpreter `%s` not accessible: %s', self._shell, err
                )
                raise error.BASICError(error.IFC)
        shell_output = self._launch_reader_thread(p.stdout)
        shell_cerr = self._launch_reader_thread(p.stderr)
        try:
            self._communicate(p, shell_output, shell_cerr)
        except EnvironmentError as e:
            logging.warning(e)
        finally:
            # ensure the process is terminated on exit
            if p.poll() is None:
                p.kill()
def launch ( self , command ) : logging . debug ( 'Executing SHELL command `%r` with command interpreter `%s`' , command , self . _shell ) if not self . _shell : logging . warning ( 'SHELL statement not enabled: no command interpreter specified.' ) raise error . BASICError ( error . IFC ) # split by whitespace but protect quotes cmd = split_quoted ( self . _shell , quote = u'"' , strip_quotes = False ) # find executable on path cmd [ 0 ] = which ( cmd [ 0 ] , path = '.' + os . pathsep + os . environ . get ( "PATH" ) ) if not cmd [ 0 ] : logging . warning ( u'SHELL: command interpreter `%s` not found.' , self . _shell ) raise error . BASICError ( error . IFC ) if command : cmd += [ SHELL_COMMAND_SWITCH , self . _codepage . bytes_to_unicode ( command , box_protect = False ) ] # get working directory; also raises IFC if current_device is CAS1 work_dir = self . _files . get_native_cwd ( ) try : p = Popen ( cmd , shell = False , cwd = work_dir , stdin = PIPE , stdout = PIPE , stderr = PIPE , # first try with HIDE_WINDOW to avoid ugly command window popping up on windows startupinfo = HIDE_WINDOW ) except EnvironmentError : try : # HIDE_WINDOW not allowed on Windows when called from console p = Popen ( cmd , shell = False , cwd = work_dir , stdin = PIPE , stdout = PIPE , stderr = PIPE , ) except EnvironmentError as err : logging . warning ( u'SHELL: command interpreter `%s` not accessible: %s' , self . _shell , err ) raise error . BASICError ( error . IFC ) shell_output = self . _launch_reader_thread ( p . stdout ) shell_cerr = self . _launch_reader_thread ( p . stderr ) try : self . _communicate ( p , shell_output , shell_cerr ) except EnvironmentError as e : logging . warning ( e ) finally : # ensure the process is terminated on exit if p . poll ( ) is None : p . kill ( )