How to use the pexpect.spawnu function in pexpect

To help you get started, we’ve selected a few pexpect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pexpect / pexpect / tests / test_unicode.py View on Github external
def test_spawn_utf8_incomplete(self):
        # This test case ensures correct incremental decoding, which
        # otherwise fails when the stream inspected by os.read()
        # does not align exactly at a utf-8 multibyte boundary:
        #    UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in
        #                        position 0: unexpected end of data
        p = pexpect.spawnu('cat', maxread=1)
        p.sendline('▁▂▃▄▅▆▇█')
        p.sendeof()
        p.expect('▁▂▃▄▅▆▇█')
github LyzardKing / grive-indicator / tests / tools.py View on Github external
def spawn_process(command):
    """return a handle to a new controllable child process"""
    return pexpect.spawnu(command, dimensions=(24, 250))
github pexpect / pexpect / tests / test_interact.py View on Github external
def test_interact_exit_unicode(self):
        " Ensure subprocess receives utf8. "
        p = pexpect.spawnu('{self.interact_py} --utf8'.format(self=self),
                           timeout=5, env=self.env)
        p.expect('READY')
        p.send('ɑ')              # >>> map(ord, u'ɑ'.encode('utf8'))
        p.expect('201
github eLVee1991 / youtubeblock / youtubeblock.py View on Github external
"""
    Uploads the contents of 'blocklist.txt' to the pihole with the command pihole -b
    """
    urls = []
    with open(block_list, 'r') as in_file:
        for line in in_file:
            with open(black_list, "r") as in_file2:
                if line in in_file2:
                    pass
                else:
                    #print(line)
                    urls.append(line.rstrip()+" ")
        all_urls = "".join(urls)  
        #print("[+] Adding "+line.rstrip()+" "+" to pihole.")
        if all_urls:    
            command = p.spawnu("pihole -b "+all_urls)
            command.interact()
            #print("[+] Done.")
            command.close()
            command1 = p.spawnu("pihole restartdns")
            command1.interact()
            command1.close()
        else:
            message("bold", "[+] No urls to add.")
    in_file.close()
github eLVee1991 / youtubeblock / youtubeblock.py View on Github external
def delete_logs():
    """
    Delete the files 
    - youtube_raw_addlist.log
    - all_queries.log
    to keep it nice and clean.
    """
    command = p.spawnu("rm -rf youtube_raw_addlist.log all_queries.log")
    command.interact()
    command.close()
github schutzwerk / CANalyzat0r / src / CANalyzat0r.py View on Github external
# Redirect exception logs to the textBrowser
        sys.excepthook = globalLoggingHandler

        # Check privileges
        if not self.checkSU():
            self.logger.info(Strings.mainTabNoSU)
            QMessageBox.warning(None, Strings.messageBoxNoticeTitle,
                                Strings.mainTabMessageBoxNoSUHint,
                                QMessageBox.Ok)
            shellcmd = "pkexec /bin/sh"
        else:
            shellcmd = "/bin/sh"

        # launch a long lived rootshell
        Globals.rootshell = pexpect.spawnu(shellcmd)
        Globals.rootshell.expect_exact(['$', '>', '#'])

        self.setupUi(self)
        atexit.register(MainWindow.cleanup)

        # Prepare main ui
        Globals.textBrowserLogs = self.textBrowserLogs
        sys.stdout.write(Strings.banner)
        # init and connect to the db
        Globals.db = Database.Database()

        # Create the tab instances
        Globals.fuzzerTabInstance = FuzzerTab(Globals.ui.tabFuzzer)
        Globals.comparerTabInstance = ComparerTab(Globals.ui.tabComparer)
        Globals.searcherTabInstance = SearcherTab(Globals.ui.tabSearcher)
        Globals.filterTabInstance = FilterTab(Globals.ui.tabFilter)
github cs50 / submit50 / opt / cs50 / submit50 / bin / submit50.py View on Github external
def run(command, password=None, cwd=None, env=None):
    """Run a command."""
    if run.verbose:
        print(command)

    # when not using --checkout, include GIT_DIR and GIT_WORK_TREE in env
    if env == None:
        env = {
            "GIT_DIR": run.GIT_DIR,
            "GIT_WORK_TREE": run.GIT_WORK_TREE
        }

    # if authentication required for command, send password when requested
    if password:
        child = pexpect.spawnu(command, env=env, cwd=cwd)

        # send output of command to stdout only if run with --verbose
        if run.verbose:
            child.logfile_read = sys.stdout

        try:
            child.expect("Password.*:")
            child.sendline(password)
            child.expect(pexpect.EOF)
        except:
            pass
        child.close()
        if child.exitstatus != 0:
            raise Error()
    else:
        output, status = pexpect.run(command, env=env, cwd=cwd, withexitstatus=True)
github bogdanvuk / pygears / docs / blog / riscv / files / setup_spike.py View on Github external
def __enter__(self):
        self.proc = pexpect.spawnu(self.cmd_line)
        self.proc.expect(Spike.PROMPT)
        self.proc.setecho(False)
        self.until(0)
        return self
github datasnakes / OrthoEvolution / Datasnakes / Orthologs / Phylogenetics / Phylip / orthophylip.py View on Github external
def dnadist(self, dnadist_output):
        dnadist = pexpect.spawnu("dnadist infile")
        dnadist.sendline("Y\r")
        dnadist.waitnoecho()
        self._rename("outfile", dnadist_output + "_dnadist")