Skip to content

Conversation

@kotfu
Copy link
Member

@kotfu kotfu commented May 10, 2018

This closes #381

@kotfu kotfu added this to the 0.9.0 milestone May 10, 2018
@kotfu kotfu self-assigned this May 10, 2018
@kotfu kotfu requested a review from tleonhardt as a code owner May 10, 2018 17:18
@codecov
Copy link

codecov bot commented May 10, 2018

Codecov Report

Merging #398 into master will increase coverage by <.01%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
+ Coverage   90.22%   90.22%   +<.01%     
==========================================
  Files           8        8              
  Lines        2526     2528       +2     
==========================================
+ Hits         2279     2281       +2     
  Misses        247      247
Impacted Files Coverage Δ
cmd2/constants.py 100% <100%> (ø) ⬆️
cmd2/parsing.py 98.27% <100%> (ø) ⬆️
cmd2/cmd2.py 91.67% <87.5%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d4d929...ceb3ef5. Read the comment docs.

kmvanbrunt
kmvanbrunt previously approved these changes May 10, 2018
REDIRECTION_OUTPUT = '>'
REDIRECTION_APPEND = '>>'
REDIRECTION_CHARS = [REDIRECTION_PIPE, REDIRECTION_OUTPUT]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of constants here

Copy link
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strongly consider adding back the shlex.split call when calling subprocess.Popen. In general it should probably be there unless Popen is called with shell=True, but that has other side effects.

# We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True.
try:
self.pipe_proc = subprocess.Popen(shlex.split(statement.pipe_to), stdin=subproc_stdin)
self.pipe_proc = subprocess.Popen(statement.pipe_to, stdin=subproc_stdin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think you want to drop the shlex.split call within the first argument of the call to subprocess.Popen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statement.pipe_to gets used in exactly one place, and it's right here. in parsing.py we took a list of shlexed tokens and joined them with a space to generate statement.pipe_to, then we split them apart to pass it to the subprocess command. I just changed statement.pipe_to to have the list of tokens, instead of a string.

Is your concern passing a string to subprocess.Popen()? I agree that would be a concern, but we are passing a list of arguments, just like we were before.

Or is there another concern?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add shell=True here anyway and switch to a string so that we can support a command like:

(Cmd) help | wc > "count it.txt"

Copy link
Member

@tleonhardt tleonhardt May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, if statement.pipe_to is already a list then we are good.

And if you think there are advantages in using shell=True we can try it. For some things it can be helpful, but other times it has messed us up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now I'll just leave it as it is with the list. That will be no change in current pipe functionality. If we want to revisit the shell=True option later, we can.

@kotfu kotfu merged commit b48d6b5 into master May 10, 2018
@kotfu kotfu deleted the remove_dynamic_redirectors branch May 10, 2018 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cmd2.redirector isn't honored any more, either make it work or deprecate it

4 participants