Python subprocess.DEVNULL Examples

The following are 30 code examples for showing how to use subprocess.DEVNULL(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module subprocess , or try the search function .

Example 1
Project: lichess-bot   Author: ShailChoksi   File: engine_wrapper.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, board, commands, options, silence_stderr=False):
        commands = commands[0] if len(commands) == 1 else commands
        self.go_commands = options.get("go_commands", {})

        self.engine = chess.uci.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)
        self.engine.uci()

        if options:
            self.engine.setoption(options)

        self.engine.setoption({
            "UCI_Variant": type(board).uci_variant,
            "UCI_Chess960": board.chess960
        })
        self.engine.position(board)

        info_handler = chess.uci.InfoHandler()
        self.engine.info_handlers.append(info_handler) 
Example 2
Project: lichess-bot   Author: ShailChoksi   File: engine_wrapper.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, board, commands, options=None, silence_stderr=False):
        commands = commands[0] if len(commands) == 1 else commands
        self.engine = chess.xboard.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)

        self.engine.xboard()

        if board.chess960:
            self.engine.send_variant("fischerandom")
        elif type(board).uci_variant != "chess":
            self.engine.send_variant(type(board).uci_variant)

        if options:
            self._handle_options(options)

        self.engine.setboard(board)

        post_handler = chess.xboard.PostHandler()
        self.engine.post_handlers.append(post_handler) 
Example 3
Project: epr   Author: wustho   File: epr.py    License: MIT License 6 votes vote down vote up
def open_media(scr, epub, src):
    sfx = os.path.splitext(src)[1]
    fd, path = tempfile.mkstemp(suffix=sfx)
    try:
        with os.fdopen(fd, "wb") as tmp:
            tmp.write(epub.file.read(src))
        # run(VWR +" "+ path, shell=True)
        subprocess.call(
            VWR + [path],
            # shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL
        )
        k = scr.getch()
    finally:
        os.remove(path)
    return k 
Example 4
Project: singer-tools   Author: singer-io   File: check_tap.py    License: Apache License 2.0 6 votes vote down vote up
def run_and_summarize(tap, config, state=None, debug=False):
    cmd = [tap, '--config', config]
    if state:
        cmd += ['--state', state]
    print('Running command {}'.format(' '.join(cmd)))

    stderr = None if debug else subprocess.DEVNULL
    tap = Popen(cmd,
                stdout=subprocess.PIPE,
                stderr=stderr,
                bufsize=1,
                universal_newlines=True)
    summarizer = StdoutReader(tap)
    summarizer.start()
    returncode = tap.wait()
    if returncode != 0:
        print('ERROR: tap exited with status {}'.format(returncode))
        exit(1)

    return summarizer.summary 
Example 5
Project: firefox_decrypt   Author: unode   File: firefox_decrypt.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_version():
    """Obtain version information from git if available otherwise use
    the internal version number
    """
    def internal_version():
        return '.'.join(map(str, __version_info__[:3])) + ''.join(__version_info__[3:])

    try:
        p = Popen(["git", "describe", "--tags"], stdout=PIPE, stderr=DEVNULL)
    except OSError:
        return internal_version()

    stdout, stderr = p.communicate()

    if p.returncode:
        return internal_version()
    else:
        # Both py2 and py3 return bytes here
        return stdout.decode(USR_ENCODING).strip() 
Example 6
Project: raveberry   Author: raveberry   File: system.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_latest_version(self, _request: WSGIRequest) -> HttpResponse:
        """Looks up the newest version number from PyPi and returns it."""
        try:
            subprocess.run(
                "pip3 install raveberry==nonexistingversion".split(),
                stdout=subprocess.DEVNULL,
                stderr=subprocess.PIPE,
                universal_newlines=True,
                check=True,
            )
        except subprocess.CalledProcessError as e:
            # parse the newest verson from pip output
            for line in e.stderr.splitlines():
                if "from versions" in line:
                    versions = [re.sub(r"[^0-9.]", "", token) for token in line.split()]
                    versions = [version for version in versions if version]
                    latest_version = versions[-1]
                    return HttpResponse(latest_version)
        return HttpResponseBadRequest("Could not determine latest version.") 
Example 7
Project: raveberry   Author: raveberry   File: sound.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def set_output_device(self, request: WSGIRequest) -> HttpResponse:
        """Sets the given device as default output device."""
        device = request.POST.get("device")
        if not device:
            return HttpResponseBadRequest("No device selected")

        try:
            subprocess.run(
                ["pactl", "set-default-sink", device],
                stdout=subprocess.DEVNULL,
                stderr=subprocess.PIPE,
                env={"PULSE_SERVER": "127.0.0.1"},
                check=True,
            )
        except subprocess.CalledProcessError as e:
            return HttpResponseBadRequest(e.stderr)
        # restart mopidy to apply audio device change
        subprocess.call(["sudo", "/usr/local/sbin/raveberry/restart_mopidy"])
        return HttpResponse(
            f"Set default output. Restarting the current song might be necessary."
        ) 
Example 8
Project: qutebrowser   Author: qutebrowser   File: asciidoc2html.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _get_asciidoc_cmd(self) -> List[str]:
        """Try to find out what commandline to use to invoke asciidoc."""
        if self._asciidoc is not None:
            return self._asciidoc

        for executable in ['asciidoc', 'asciidoc.py']:
            try:
                subprocess.run([executable, '--version'],
                               stdout=subprocess.DEVNULL,
                               stderr=subprocess.DEVNULL,
                               check=True)
            except OSError:
                pass
            else:
                return [executable]

        raise FileNotFoundError 
Example 9
Project: frigate   Author: blakeblackshear   File: video.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def start_or_restart_ffmpeg(ffmpeg_cmd, frame_size, ffmpeg_process=None):
    if not ffmpeg_process is None:
        print("Terminating the existing ffmpeg process...")
        ffmpeg_process.terminate()
        try:
            print("Waiting for ffmpeg to exit gracefully...")
            ffmpeg_process.communicate(timeout=30)
        except sp.TimeoutExpired:
            print("FFmpeg didnt exit. Force killing...")
            ffmpeg_process.kill()
            ffmpeg_process.communicate()
        ffmpeg_process = None

    print("Creating ffmpeg process...")
    print(" ".join(ffmpeg_cmd))
    process = sp.Popen(ffmpeg_cmd, stdout = sp.PIPE, stdin = sp.DEVNULL, bufsize=frame_size*10, start_new_session=True)
    return process 
Example 10
Project: discord.py   Author: Rapptz   File: player.py    License: MIT License 6 votes vote down vote up
def __init__(self, source, *, executable='ffmpeg', pipe=False, stderr=None, before_options=None, options=None):
        args = []
        subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}

        if isinstance(before_options, str):
            args.extend(shlex.split(before_options))

        args.append('-i')
        args.append('-' if pipe else source)
        args.extend(('-f', 's16le', '-ar', '48000', '-ac', '2', '-loglevel', 'warning'))

        if isinstance(options, str):
            args.extend(shlex.split(options))

        args.append('pipe:1')

        super().__init__(source, executable=executable, args=args, **subprocess_kwargs) 
Example 11
Project: cassandra-dtest   Author: apache   File: dtest.py    License: Apache License 2.0 6 votes vote down vote up
def cleanup_docker_environment_before_test_execution():
    """
    perform a bunch of system cleanup operations, like kill any instances that might be
    hanging around incorrectly from a previous run, sync the disk, and clear swap.
    Ideally we would also drop the page cache, but as docker isn't running in privileged
    mode there is no way for us to do this.
    """
    # attempt to wack all existing running Cassandra processes forcefully to get us into a clean state
    p_kill = subprocess.Popen('ps aux | grep -ie CassandraDaemon | grep java | grep -v grep | awk \'{print $2}\' | xargs kill -9',
                              stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
    p_kill.wait(timeout=10)

    # explicitly call "sync" to flush everything that might be pending from a previous test
    # so tests are less likely to hit a very slow fsync during the test by starting from a 'known' state
    # note: to mitigate this further the docker image is mounting /tmp as a volume, which gives
    # us an ext4 mount which should talk directly to the underlying device on the host, skipping
    # the aufs pain that we get with anything else running in the docker image. Originally,
    # I had a timeout of 120 seconds (2 minutes), 300 seconds (5 minutes) but sync was still occasionally timing out.
    p_sync = subprocess.Popen('sudo /bin/sync', shell=True)
    p_sync.wait(timeout=600)

    # turn swap off and back on to make sure it's fully cleared if anything happened to swap
    # from a previous test run
    p_swap = subprocess.Popen('sudo /sbin/swapoff -a && sudo /sbin/swapon -a', shell=True)
    p_swap.wait(timeout=60) 
Example 12
Project: codimension   Author: SergeySatskiy   File: plantumlcache.py    License: GNU General Public License v3.0 6 votes vote down vote up
def run(self):
        """Runs plantUML"""
        srcFile = self.__fName[:-3] + 'txt'
        try:
            # Run plantUML
            saveToFile(srcFile, self.__source)
            retCode = subprocess.call(['java', '-jar', JAR_PATH,
                                       '-charset', 'utf-8', '-nometadata',
                                       srcFile],
                                      stdout=subprocess.DEVNULL,
                                      stderr=subprocess.DEVNULL)
            self.safeUnlink(srcFile)

            if retCode == 0:
                self.sigFinishedOK.emit(self.__md5, self.__uuid, self.__fName)
            else:
                self.sigFinishedError.emit(self.__md5, self.__fName)
        except Exception as exc:
            logging.error('Cannot render a plantUML diagram: %s', str(exc))
            self.safeUnlink(srcFile)
            self.sigFinishedError.emit(self.__md5, self.__fName) 
Example 13
Project: smriprep   Author: nipreps   File: smriprep_docker.py    License: Apache License 2.0 6 votes vote down vote up
def _run(args, stdout=None, stderr=None):
        from collections import namedtuple
        result = namedtuple('CompletedProcess', 'stdout stderr returncode')

        devnull = None
        if subprocess.DEVNULL in (stdout, stderr):
            devnull = open(os.devnull, 'r+')
            if stdout == subprocess.DEVNULL:
                stdout = devnull
            if stderr == subprocess.DEVNULL:
                stderr = devnull

        proc = subprocess.Popen(args, stdout=stdout, stderr=stderr)
        stdout, stderr = proc.communicate()
        res = result(stdout, stderr, proc.returncode)

        if devnull is not None:
            devnull.close()

        return res 
Example 14
Project: vidgear   Author: abhiTronix   File: helper.py    License: Apache License 2.0 6 votes vote down vote up
def check_output(*args, **kwargs):
    """
    ### check_output

    Returns stdin output from subprocess module
    """
    # import libs
    import subprocess as sp
    from subprocess import DEVNULL

    # execute command in subprocess
    process = sp.Popen(stdout=sp.PIPE, stderr=DEVNULL, *args, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()

    # if error occurred raise error
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = args[0]
        error = sp.CalledProcessError(retcode, cmd)
        error.output = output
        raise error
    return output 
Example 15
Project: benchexec   Author: sosy-lab   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def write_table_in_format(template_format, outfile, options, **kwargs):
    callback = {"csv": write_csv_table, "html": htmltable.write_html_table}[
        template_format
    ]

    if outfile:
        # Force HTML file to be UTF-8 regardless of system encoding because it actually
        # declares itself to be UTF-8 in a meta tag.
        encoding = "utf-8" if template_format == "html" else None
        with open(outfile, "w", encoding=encoding) as out:
            callback(out, options=options, **kwargs)

        if options.show_table and template_format == "html":
            try:
                subprocess.Popen(
                    ["xdg-open", outfile],
                    stdout=subprocess.DEVNULL,
                    stderr=subprocess.DEVNULL,
                )
            except OSError:
                pass

    else:
        callback(sys.stdout, options=options, **kwargs) 
Example 16
Project: wwrando   Author: LagoLunatic   File: disassemble.py    License: MIT License 6 votes vote down vote up
def disassemble_file(bin_path, asm_path):
  command = [
    r"C:\devkitPro\devkitPPC\bin\powerpc-eabi-objdump.exe",
    "--disassemble-zeroes",
    "-m", "powerpc",
    "-D",
    "-b", "binary",
    "-EB",
    bin_path
  ]
  
  print(" ".join(command))
  print()
  with open(asm_path, "wb") as f:
    result = call(command, stdout=f, stdin=DEVNULL, stderr=DEVNULL)
  if result != 0:
    raise Exception("Disassembler call failed") 
Example 17
Project: renpy-shader   Author: bitsawer   File: util.py    License: MIT License 6 votes vote down vote up
def _get_soname(f):
            if not f:
                return None

            try:
                proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. command not found
                return None
            with proc:
                data = proc.stdout.read()
            res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
            if not res:
                return None
            return os.fsdecode(res.group(1)) 
Example 18
Project: renpy-shader   Author: bitsawer   File: util.py    License: MIT License 6 votes vote down vote up
def _get_soname(f):
            # assuming GNU binutils / ELF
            if not f:
                return None
            objdump = shutil.which('objdump')
            if not objdump:
                # objdump is not available, give up
                return None

            try:
                proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. bad executable
                return None
            with proc:
                dump = proc.stdout.read()
            res = re.search(br'\sSONAME\s+([^\s]+)', dump)
            if not res:
                return None
            return os.fsdecode(res.group(1)) 
Example 19
Project: renpy-shader   Author: bitsawer   File: util.py    License: MIT License 6 votes vote down vote up
def find_library(name):
            ename = re.escape(name)
            expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
            expr = os.fsencode(expr)

            try:
                proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.DEVNULL)
            except OSError:  # E.g. command not found
                data = b''
            else:
                with proc:
                    data = proc.stdout.read()

            res = re.findall(expr, data)
            if not res:
                return _get_soname(_findLib_gcc(name))
            res.sort(key=_num_version)
            return os.fsdecode(res[-1]) 
Example 20
Project: bob   Author: BobBuildTool   File: archive.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _openDownloadFile(self, buildId, suffix):
        (tmpFd, tmpName) = mkstemp()
        url = self._makeUrl(buildId, suffix)
        try:
            os.close(tmpFd)
            env = { k:v for (k,v) in os.environ.items() if k in self.__whiteList }
            env["BOB_LOCAL_ARTIFACT"] = tmpName
            env["BOB_REMOTE_ARTIFACT"] = url
            ret = subprocess.call(["/bin/bash", "-ec", self.__downloadCmd],
                stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
                cwd="/tmp", env=env)
            if ret == 0:
                ret = tmpName
                tmpName = None
                return CustomDownloader(ret)
            else:
                raise ArtifactDownloadError("failed (exit {})".format(ret))
        finally:
            if tmpName is not None: os.unlink(tmpName) 
Example 21
Project: btcpy   Author: chainside   File: regtest.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def start_nodes(self):
        for node in self.nodes:
            data_dir = os.path.abspath('{}/node_{}'.format(self.regtest_path, node))
            conf = os.path.abspath('{}/bitcoin.conf'.format(data_dir))
            cmd = ['bitcoind', '-conf={}'.format(conf), '-datadir={}'.format(data_dir),
                   '-maxtxfee=1000', '-debug=1', '-prematurewitness', '-zmqpubrawblock=tcp://127.0.0.1:28332']
            # cmd = ['/home/rael/bitcoin/src/bitcoind', '-conf={}'.format(conf), '-datadir={}'.format(data_dir),
            #        '-maxtxfee=100', '-debug=1', '-prematurewitness']
            subprocess.call(cmd)  # , stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

            self.nodes[node] = {'user': Manager.user,
                                'password': Manager.password,
                                'host': Manager.host,
                                'port': Manager.base_port + node,
                                'rpcport': Manager.base_rpcport + node}

        sleep(3)

        for n in self.nodes:
            for m in self.nodes:
                if m != n:
                    self.send_rpc_cmd(['addnode',
                                       '{}:{}'.format(Manager.host, self.nodes[m]['port']),
                                       'onetry'],
                                      n) 
Example 22
Project: Blueproximity   Author: Thor77   File: device.py    License: GNU General Public License v2.0 6 votes vote down vote up
def distance(self):
        '''
        Determinte distance of the device

        :return: distance of the device
        :rtype: int
        '''
        if not self.connected:
            logger.debug('Device disconnected -> reconnecting')
            self.connect()
        p = subprocess.run(
            ['hcitool', 'rssi', self.mac],
            stdout=subprocess.PIPE,
            stderr=subprocess.DEVNULL
        )
        if p.returncode == 0:
            match = rssi_re.match(p.stdout.decode('utf-8'))
            if match:
                return abs(int(match.group(1)))
        return 255 
Example 23
Project: px   Author: genotrance   File: test.py    License: MIT License 6 votes vote down vote up
def remoteTest(port, fail=False):
    lip = 'echo $SSH_CLIENT ^| cut -d \\\" \\\" -f 1,1'
    cmd = os.getenv("REMOTE_SSH")
    if cmd is None:
        print("  Skipping: Remote test - REMOTE_SSH not set")
        return
    cmd = cmd + " curl --proxy `%s`:%s --connect-timeout 2 -s http://google.com" % (lip, port)
    sys.stdout.write("  Checking: Remote:" + str(port) + " = ")
    ret = subprocess.call(cmd, stdout=DEVNULL, stderr=DEVNULL)
    if (ret == 0 and fail == False) or (ret != 0 and fail == True) :
        print(str(ret) + ": Passed")
    else:
        print(str(ret) + ": Failed")
        return False

    return True 
Example 24
Project: pkmeter   Author: pkkid   File: system.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def open_system_monitor(self, widget):
        cmd = '/usr/bin/gnome-system-monitor -r'
        log.info('Opening system monitor: %s', cmd)
        Popen(shlex.split(cmd), stdout=DEVNULL, stderr=DEVNULL) 
Example 25
Project: pkmeter   Author: pkkid   File: processes.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def open_system_monitor(self, widget):
        cmd = '/usr/bin/gnome-system-monitor -p'
        log.info('Opening system monitor: %s', cmd)
        Popen(shlex.split(cmd), stdout=DEVNULL, stderr=DEVNULL) 
Example 26
Project: multibootusb   Author: mbusb   File: _7zip.py    License: GNU General Public License v2.0 5 votes vote down vote up
def list_iso(iso_link, suppress_out=True, expose_exception=False):
    """
    List the content of ISO files. It does'nt work with non 'utf' characters (simply ignores them).
    :param iso_link:Path to ISO link
    :param suppress_out: Option to suppress output to stdout. Default True.
    :return: Path to files and directories as a list
    """
    if platform.system() == 'Windows':
        if suppress_out is True:
            suppress_out = ' 2> nul'
    else:
        if suppress_out is True:
            suppress_out = ' 2> /dev/null'
    if not os.path.exists(iso_link):
        gen.log('Path to ISO link does not exist.')
        return False
    else:
        file_list = []
        _cmd = _7zip + ' l ' + gen.quote(iso_link) + suppress_out
        try:
            _cmd_out = subprocess.check_output(_cmd, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL,
                                               shell=True).decode('utf-8', 'ignore').splitlines()
        except Exception as e:
            gen.log(e)
            if expose_exception:
                raise
            _cmd_out = ''
        for line in _cmd_out:
            if '...' in line:
                line = line.split()
                _path = line[-1]
                file_list.append(_path)
        return file_list 
Example 27
Project: arxiv-collector   Author: djsutherland   File: arxiv_collector.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_latexmk_version(latexmk="latexmk"):
    with io.open(os.devnull, "w") as devnull:  # subprocess.DEVNULL is 3.3+
        out = subprocess.check_output([latexmk, "--version"], stderr=devnull).decode()

    match = version_re.search(out)
    if not match:
        raise ValueError("Bad output of {} --version:\n{}".format(latexmk, out))
    return match.group(1)


# based on https://stackoverflow.com/a/1094933/344821 
Example 28
Project: wuy   Author: manatlan   File: wuy.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, url, size=None, chromeArgs=[]):
        self.__instance = None

        if sys.platform[:3] == "win":
            exe = find_chrome_win()
        elif sys.platform == "darwin":
            exe = find_chrome_mac()
        else:
            for i in ["chromium-browser", "chromium", "google-chrome", "chrome"]:
                try:
                    exe = webbrowser.get(i).name
                    break
                except webbrowser.Error:
                    exe = None

        if exe:
            args = [exe, "--app=" + url] + chromeArgs
            if size == FULLSCREEN:
                args.append("--start-fullscreen")
            if tempfile.gettempdir():
                args.append(
                    "--user-data-dir=%s"
                    % os.path.join(tempfile.gettempdir(), ".wuyapp")
                )
            # self.__instance = subprocess.Popen( args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) # make troubles on windows (freezd with noconsole don't start)
            self.__instance = subprocess.Popen(args)
        else:
            raise Exception("no browser") 
Example 29
Project: typeshed   Author: python   File: pytype_test.py    License: Apache License 2.0 5 votes vote down vote up
def can_run(exe: str, *, args: List[str]) -> bool:
    try:
        subprocess.run([exe] + args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    except OSError:
        return False
    else:
        return True 
Example 30
Project: imgcomp-cvpr   Author: fab-jul   File: other_codecs.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _decode_webp_to_png(webp_p):
    png_p = webp_p.replace('.webp', '_as_png.png')
    subprocess.call([DWEBP, webp_p, '-o', png_p], stderr=subprocess.DEVNULL)
    return png_p