Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conda run adds an extra newline to the output #11763

Open
2 tasks done
jmarshall opened this issue Aug 26, 2022 · 0 comments
Open
2 tasks done

conda run adds an extra newline to the output #11763

jmarshall opened this issue Aug 26, 2022 · 0 comments
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release good first issue great for new contributors, code change is envisioned to be trivial/relatively straight-forward plugins::run pertains to conda-run source::community catch-all for issues filed by community members type::bug describes erroneous operation, use severity::* to classify the type

Comments

@jmarshall
Copy link

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

Running a command via conda run adds an extra newline (when the output is non-empty):

(base) $ conda run true
(base) $ conda run echo hello
hello

(base) $ 

When shell redirection is naively applied to the conda run command (rather than to the subcommand to be executed, though getting that right would require careful and fragile quoting if it is possible at all), this leads to the captured output having an extra blank line at the end of it. Where that captured output is to be processed by another program, this can lead to syntax errors, e.g., as seen in lh3/bwa#371.

In that issue, this can be avoided by using the subcommand's -o option instead of redirecting output. But such options are not alway available, and users often use the familiar redirection even when the subcommand has such an option.

This can be avoided with --no-capture-output if the user knows about that option:

(base) $ conda run --no-capture-output echo hello
hello
(base) $ 

but it would be beneficial if conda run did not alter the output by default as well.

The code in question is in conda/cli/main_run.py:

# display stdout/stderr if it was captured
if not args.no_capture_output:
if response.stdout:
print(response.stdout, file=sys.stdout)
if response.stderr:
print(response.stderr, file=sys.stderr)

It would be a simple fix to add …, end='', … to the print calls, or, if it was preferred, to only add an extra newline if the last character of the (non-empty) output is not already a newline.

Conda Info

No response

Conda Config

No response

Conda list

No response

Additional Context

No response

@jmarshall jmarshall added the type::bug describes erroneous operation, use severity::* to classify the type label Aug 26, 2022
@kenodegard kenodegard added source::community catch-all for issues filed by community members good first issue great for new contributors, code change is envisioned to be trivial/relatively straight-forward plugins::run pertains to conda-run backlog issue has been triaged but has not been earmarked for any upcoming release labels Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release good first issue great for new contributors, code change is envisioned to be trivial/relatively straight-forward plugins::run pertains to conda-run source::community catch-all for issues filed by community members type::bug describes erroneous operation, use severity::* to classify the type
Projects
Status: No status
Development

No branches or pull requests

2 participants