Project Name: MrTango+click
Language: Python
Statement Type: API

Source Code:
def _pipepager(text, cmd, color):
    """Page through text by feeding it to another program.  Invoking a
    pager through this might support colors.
    """
    import subprocess
    env = dict(os.environ)

    # If we're piping to less we might support colors under the
    # condition that
    cmd_detail = cmd.rsplit('/', 1)[-1].split()
    if color is None and cmd_detail[0] == 'less':
        less_flags = os.environ.get('LESS', '') + ' '.join(cmd_detail[1:])
        if not less_flags:
            env['LESS'] = '-R'
            color = True
        elif 'r' in less_flags or 'R' in less_flags:
            color = True

    if not color:
        text = strip_ansi(text)

    c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
                         env=env)
    encoding = get_best_encoding(c.stdin)
    try:
        c.stdin.write(text.encode(encoding, 'replace'))
        c.stdin.close()
    except (IOError, KeyboardInterrupt):
        pass

    # Less doesn't respect ^C, but catches it for its own UI purposes (aborting
    # search or other commands inside less).
    #
    # That means when the user hits ^C, the parent process (click) terminates,
    # but less is still alive, paging the output and messing up the terminal.
    #
    # If the user wants to make the pager exit on ^C, they should set
    # `LESS='-K'`. It's not our decision to make.
    while True:
        try:
            c.wait()
        except KeyboardInterrupt:
            pass
        else:
            break

_pipepager(text='haha\n', cmd='cat', color=None)

Selected Statement: c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,

Function Input:
text: 'haha\n'
cmd: 'cat'
color: None

Variable Values Before Statement:
cmd: 'cat'

Value After Statement Execution: <Popen: returncode: None args: 'cat'>

Variable States During Runtime (line, value):
text: 1
'haha\n'
cmd: 1
'cat'
color: 1
None
subprocess: 5
<module 'subprocess' from '/local/rcs/jinjun/miniforge3/envs/MrTango+click/lib/python3.9/subprocess.py'>
env: 6
{'SHELL': '/bin/bash', 'LSCOLORS': 'Gxfxcxdxbxegedabagacad', 'USER_ZDOTDIR': '/home/jinjun', 'COLORTERM': 'truecolor', 'LESS': '-R', 'TERM_PROGRAM_VERSION': '3.2a', 'GVM_VERSION': '1.0.22', 'CONDA_EXE': '/local/rcs/jinjun/miniforge3/bin/conda', '_CE_M': '', 'TMUX': '/tmp/tmux-19200/default,59951,3', 'PKG_CONFIG_PATH': '/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib/pkgconfig:/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib/pkgconfig:', '_P9K_TTY': '/dev/pts/20', 'GVM_PATH_BACKUP': '/home/jinjun/.gvm/bin:/local/rcs/jinjun/miniforge3/envs/mal/bin:/local/rcs/jinjun/miniforge3/condabin:/home/jinjun/.gdrive-downloader:/local/arise/jinjun/miniforge3/bin:/home/jinjun/.gvm/pkgsets/go1.19.1/global/bin:/home/jinjun/.gvm/gos/go1.19.1/bin:/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/bin:/home/jinjun/.gvm/bin:/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/jinjun/.local/bin:/home/jinjun/.local/bin:/home/jinjun/.local/bin', 'P9K_TTY': 'old', 'LC_FIG_SET_PARENT': '4c022497-5122-4b80-b325-c89bab32302a', 'PWD': '/local/rcs/jinjun/code/pytrace-collector/logs/pypibugs/tried/MrTango+click/MrTango+click', 'LOGNAME': 'jinjun', 'XDG_SESSION_TYPE': 'tty', 'CONDA_PREFIX': '/local/rcs/jinjun/miniforge3/envs/MrTango+click', 'VSCODE_GIT_ASKPASS_NODE': '/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/node', 'MOTD_SHOWN': 'pam', 'VSCODE_INJECTION': '1', 'GVM_OVERLAY_PREFIX': '/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay', 'HOME': '/home/jinjun', 'LANG': 'en_US.UTF-8', 'DYLD_LIBRARY_PATH': '/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib:/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:', 'gvm_pkgset_name': 'global', 'SSL_CERT_DIR': '/usr/lib/ssl/certs', 'CONDA_PROMPT_MODIFIER': '(MrTango+click) ', 'GIT_ASKPASS': '/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/extensions/git/dist/askpass.sh', 'GVM_ROOT': '/home/jinjun/.gvm', 'SSH_CONNECTION': '127.0.0.1 39996 127.0.0.1 22', 'GOROOT': '/home/jinjun/.gvm/gos/go1.19.1', 'NVM_DIR': '/local/rcs/jinjun/.nvm', 'VSCODE_GIT_ASKPASS_EXTRA_ARGS': '', 'XDG_SESSION_CLASS': 'user', 'PYTHONPATH': ':/local/rcs/jinjun/code/pytrace-collector:/local/rcs/jinjun/code/pytrace-collector/logs/pypibugs/tried/MrTango+click/MrTango+click', 'TERM': 'screen', 'ZSH': '/home/jinjun/.oh-my-zsh', '_CE_CONDA': '', 'VSCODE_NONCE': 'd0bc7031-48a3-4719-8bb5-ef236ddd0016', 'ZDOTDIR': '/home/jinjun', 'USER': 'jinjun', 'TMUX_PANE': '%3', 'VSCODE_GIT_IPC_HANDLE': '/run/user/19200/vscode-git-13d67c6199.sock', 'CONDA_SHLVL': '3', 'SHLVL': '3', 'PAGER': 'cat', '_P9K_SSH_TTY': '/dev/pts/20', 'XDG_SESSION_ID': '43', 'CONDA_PYTHON_EXE': '/local/rcs/jinjun/miniforge3/bin/python', 'LD_LIBRARY_PATH': '/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib:/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/lib', 'XDG_RUNTIME_DIR': '/run/user/19200', 'SSL_CERT_FILE': '/usr/lib/ssl/certs/ca-certificates.crt', 'SSH_CLIENT': '127.0.0.1 46946 22', 'CONDA_DEFAULT_ENV': 'MrTango+click', 'P9K_SSH': '1', 'LC_ALL': 'en_US.UTF-8', 'VSCODE_GIT_ASKPASS_MAIN': '/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/extensions/git/dist/askpass-main.js', 'XDG_DATA_DIRS': '/usr/local/share:/usr/share:/var/lib/snapd/desktop', 'BROWSER': '/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/bin/helpers/browser.sh', 'PATH': '/home/jinjun/.gdrive-downloader:/local/arise/jinjun/miniforge3/bin:/home/jinjun/.gvm/pkgsets/go1.19.1/global/bin:/home/jinjun/.gvm/gos/go1.19.1/bin:/home/jinjun/.gvm/pkgsets/go1.19.1/global/overlay/bin:/home/jinjun/.gvm/bin:/local/rcs/jinjun/miniforge3/envs/MrTango+click/bin:/local/rcs/jinjun/miniforge3/condabin:/home/jinjun/.gdrive-downloader:/local/arise/jinjun/miniforge3/bin:/home/jinjun/.vscode-server/cli/servers/Stable-31c37ee8f63491495ac49e43b8544550fbae4533/server/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/jinjun/.local/bin:/home/jinjun/.local/bin', 'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/19200/bus', 'gvm_go_name': 'go1.19.1', 'CONDA_PREFIX_1': '/local/rcs/jinjun/miniforge3', 'CONDA_PREFIX_2': '/local/rcs/jinjun/miniforge3/envs/mal', 'OLDPWD': '/local/rcs/jinjun/code/pytrace-collector', 'GOPATH': '/home/jinjun/.gvm/pkgsets/go1.19.1/global', 'TERM_PROGRAM': 'tmux', 'VSCODE_IPC_HOOK_CLI': '/run/user/19200/vscode-ipc-518d6355-acaf-4714-a359-be3fe9f21e09.sock', '_': '/local/rcs/jinjun/miniforge3/envs/MrTango+click/bin/python', 'PYTEST_CURRENT_TEST': 'tests/test_utils.py::test_echo_via_pager[cat] (call)'}
cmd_detail: 10
cat
c: 22
<Popen: returncode: None args: 'cat'>
41
<Popen: returncode: 0 args: 'cat'>
encoding: 24
'utf-8'