Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous implementation for piping command output to a shell command utilized a temporary file and only once the command was completely done did it "pipe" the command output to the shell command by using the temporary file as the commands input. This approach had many disadvantages, including:
Now a real pipe is created to a subprocess. This approach should "just work like intended" with all commands and has many advantages, including:
One downside is to work properly on Python 2.7, it requires the subprocess32 module which is the subprocess module from Python 3.2 backported to Python 2.7. Another downside, is that unit testing the feature is now more difficult.
A more subtle downside is that users now need to be careful when designing multi-threaded cmd2 applications that do command processing in other threads where those threads can make calls to self.stdout.write. If the end user does something to manually close the piped shell command before the cmd2 command is finished executing, then a BrokenPipe exception can occur. This is easily fixed by putting a try/except to catch Broken Pipe errors in one strategic location in your code. You just need to be aware of this.
This closes #197