bash icon indicating copy to clipboard operation
bash copied to clipboard

The 'increasingly useful' case does not work

Open peterjpxie opened this issue 5 years ago • 0 comments

The 'increasingly useful' case in Readme.rst seems to show when we initialize bash object, it keeps the standard output as same input for all subsequent bash function calls. But it is not the case. Instead, each bash object initialization or bash function call will update the standard output as input for next bash call in a chain fashion.

Snippet from Readme.rst: This becomes increasingly useful if you later need to reuse one such command::

>>> b = bash('ls . ')
>>> b.bash('grep ".pyc"')
bash.pyc
tests.pyc
>>> b.bash('grep ".py$"')
bash.py
tests.py

Actual Result:

>>> b = bash('ls tmp')
>>> b
a.txt
bash.py
bash.pyc
tests.py
tests.pyc
>>> b.bash('grep ".pyc"')
bash.pyc
tests.pyc
>>> b.bash('grep ".py$"')

[Note: The output is actually empty.]

code snippet:

    def sync(self, timeout=None):
        kwargs = {'input': self.stdout}  # 2. use previous stdout as input for next run
        if timeout:
            kwargs['timeout'] = timeout
            if not SUBPROCESS_HAS_TIMEOUT:
                raise ValueError(
                    "Timeout given but subprocess doesn't support it. "
                    "Install subprocess32 and try again."
                )
        self.stdout, self.stderr = self.p.communicate(**kwargs)  # 1. update self.stdout each run

Suggestion: Revise this case in readme.

peterjpxie avatar Sep 25 '19 03:09 peterjpxie