amoffat / sh

Python process launching

Home Page:https://sh.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

piping not working

dhkim09a opened this issue · comments

Environment

  • Python version: Python 3.10.10
  • OS: macOS Ventura 13.4.1 (c)

Error reproduction code 1

import sh

print(sh.cat(sh.echo('hello'), '-'))

Error reproduction code 2

import sh

print(sh.cat(sh.echo('hello', _piped=True), '-'))

Outcome with sh==2.0.4

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print(sh.cat(sh.echo('hello', _piped=True), '-'))
  File ".venv/lib/python3.10/site-packages/sh.py", line 1524, in __call__
    rc = self.__class__.RunningCommandCls(cmd, call_args, stdin, stdout, stderr)
  File ".venv/lib/python3.10/site-packages/sh.py", line 750, in __init__
    self.wait()
  File ".venv/lib/python3.10/site-packages/sh.py", line 812, in wait
    self.handle_command_exit_code(exit_code)
  File ".venv/lib/python3.10/site-packages/sh.py", line 839, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1:

  RAN: /usr/local/opt/coreutils/libexec/gnubin/cat '' -

  STDOUT:


  STDERR:
cat: '': No such file or directory

Outcome with sh==2.0.0

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print(sh.cat(sh.echo('hello'), '-'))
  File ".venv/lib/python3.10/site-packages/sh.py", line 1523, in __call__
    rc = self.__class__.RunningCommandCls(cmd, call_args, stdin, stdout, stderr)
  File ".venv/lib/python3.10/site-packages/sh.py", line 749, in __init__
    self.wait()
  File ".venv/lib/python3.10/site-packages/sh.py", line 811, in wait
    self.handle_command_exit_code(exit_code)
  File ".venv/lib/python3.10/site-packages/sh.py", line 838, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1:

  RAN: /usr/local/opt/coreutils/libexec/gnubin/cat 'hello
' -

  STDOUT:


  STDERR:
cat: 'hello'$'\n': No such file or directory

Outcome with sh==1.14.3

hello

Piping changed in 2.0. See https://github.com/amoffat/sh/blob/develop/MIGRATION.md#piping-to-stdin

Thanks! It seems the document is under update yet.

Yup, that's tracked in #656