Repository: xonsh/xonsh

Issue:
!() output sometimes silently dropped
When calling !(), some of the properties of the result (output, input, errors, etc) seem to be inaccessible unless stored in a variable first, and unless that variable is explicitly used.

For example, this works:
```
$ x = !(fortune)
$ x
CommandPipeline(stdin=<_io.BytesIO object at 0x7f0835264620>, stdout=<_io.BytesIO object at 0x7f08352640f8>, stderr=<_io.BytesIO object at 0x7f08352645c8>, pid=13632, returncode=0, args=['fortune'], alias=None, stdin_redirect=['<stdin>', 'r'], stdout_redirect=[48, 'wb'], stderr_redirect=[52, 'w'], timestamps=[1531810835.0349774, 1531810836.2735503], executed_cmd=['/usr/games/fortune'], input=, output=You are wise, witty, and wonderful, but you spend too much time reading
this sort of trash.
, errors=None)
$ x.output
'You are wise, witty, and wonderful, but you spend too much time reading\nthis sort of trash.\n'
```

Note that I typed `x` by itself on line 2. If I drop that, then I get no output:
```
$ x = !(fortune)
$ x.output
''
```

But, strangely enough. using `x.out` works, every time!
```
$ x = !(fortune)
$ x.out
'Extreme fear can neither fight nor fly.\n\t\t-- William Shakespeare, "The Rape of Lucrece"\n'
$ x = !(fortune)
$ x.out
'This life is yours.  Some of it was given to you; the rest, you made yourself.\n'
$ x = !(fortune)
$ x.out
'Q:\tWhy did the WASP cross the road?\nA:\tTo get to the middle.\n'
$ x = !(fortune)
$ x.output
''
```

This, basically never works:
```
$ !(fortune).output
''
```

My xonfig:

```
+------------------+----------------------+
| xonsh            | 0.7.0                |
| Git SHA          | 3779e8b5             |
| Commit Date      | Jul 14 14:40:04 2018 |
| Python           | 3.5.2                |
| PLY              | 3.9                  |
| have readline    | True                 |
| prompt toolkit   | 1.0.15               |
| shell type       | prompt_toolkit1      |
| pygments         | None                 |
| on posix         | True                 |
| on linux         | True                 |
| distro           | neon                 |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```


Discussion:
Hi @battaglia01! Thanks for pointing this out. There are some slightly subtle bugs here, but you are right about some of the issues.  However, I should point out that `x.output` is supposed to be non-blocking (even though it is not correctly returning) while `x.out` is the blocking version.  

Resolving patch:
diff --git a/xonsh/proc.py b/xonsh/proc.py
--- a/xonsh/proc.py
+++ b/xonsh/proc.py
@@ -2181,9 +2181,13 @@ def inp(self):
 
     @property
     def output(self):
-        if self._output is None:
-            self._output = ''.join(self.lines)
-        return self._output
+        """Non-blocking, lazy access to output"""
+        if self.ended:
+            if self._output is None:
+                self._output = ''.join(self.lines)
+            return self._output
+        else:
+            return ''.join(self.lines)
 
     @property
     def out(self):


Test patch: