Esempio n. 1
0
File: spawn.py Progetto: kant/4bars
    def local_run_get_out_raw(name, cmd):
        proc1 = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True,
                                 preexec_fn=os.setsid)
        out = proc1.communicate()

        if proc1.returncode != 0:
            Static.msg_bold("FAIL", name.upper())
            sys.stdout.write(out[1])
            raise SystemExit(32)

        return out[0]
Esempio n. 2
0
File: spawn.py Progetto: kant/4bars
    def local_run_long(name, cmd):
        proc1 = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True,
                                 preexec_fn=os.setsid)

        while proc1.returncode is None:
            for line in proc1.stdout:
                sys.stdout.write(line)
            proc1.poll()

        if proc1.returncode != 0:
            Static.msg_bold("FAIL", name.upper())
            for line in iter(proc1.stderr.readline, ''):
                sys.stdout.write(line)
            raise SystemExit(32)
Esempio n. 3
0
File: spawn.py Progetto: kant/4bars
    def local_run_realtime_continue_on_fail(name, cmd):
        proc1 = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True)

        # Poll process for new output until finished
        while True:
            nextline = proc1.stdout.readline()
            if nextline == '' and proc1.poll() is not None:
                break
            sys.stdout.write(nextline)
            sys.stdout.flush()

        output = proc1.communicate()
        if proc1.returncode != 0:
            Static.msg_bold("FAIL {0}".format(name.upper()), output[1])
Esempio n. 4
0
File: spawn.py Progetto: kant/4bars
    def local_sudo_prompt_run(name, cmd):
        password = None
        if not os.geteuid() == 0:
            print()
            print("You must be root to run this command.")
            print()
            password = getpass.getpass()
            print()

        #proc1 = subprocess.Popen(['sudo', '-p', '-k', '-S', cmd], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        proc1 = subprocess.Popen('/usr/bin/sudo -p -k -S {0}'.format(cmd),
                                 shell=True,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        out = proc1.communicate(input='{0}\n'.format(password))

        if proc1.returncode != 0:
            Static.msg_bold(
                "Password failed most likely. Possibly some other error. Inspect below.",
                name.upper())
            print(out)
            raise SystemExit(32)