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

WISH: Output messages and progress to stderr (instead of stdout) #217

Open
HenrikBengtsson opened this issue Apr 14, 2022 · 4 comments
Open
Labels
pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding source::community catch-all for issues filed by community members stale::recovered [bot] recovered after being marked as stale type::feature request for a new feature or capability

Comments

@HenrikBengtsson
Copy link

It looks like conda-pack outputs messages and progress to standard output;

$ conda activate myenv
(myenv) $ conda-pack --version
conda-pack 0.7.0
(myenv) $ conda-pack > stdout 2> stderr
(myenv) $ ls -l stdout stderr
-rw-rw-r-- 1 hb hb     0 Apr 14 12:08 stderr
-rw-rw-r-- 1 hb hb 20171 Apr 14 12:09 stdout
(myenv) $ cat stdout
Collecting packages...
Packing environment at '/home/hb/.conda/envs/myenv' to 'myenv.tar.gz'
[########################################] | 100% Completed | 30.0s

I think it would be more in line with the Unix-philosophy for such output, meant for human consumption, to go to standard error, and leave output to stdout to be consumed by software, e.g. via Unix pipe and likes. This way, you can safely do things such as:

mytool() {
  conda-pack
  echo "DONE"
}
$ res=$(mytool)
Collecting packages...
Packing environment at '/home/hb/.conda/envs/myenv' to 'myenv.tar.gz'
[########################################] | 100% Completed | 30.0s
$ echo "res=$res"
DONE

As it is now, res contains also those messages and the progress bar.

@HenrikBengtsson
Copy link
Author

Forgot to say, in case someone runs into this, a workaround is to redirect stdout ("1") to stderr ("2") using:

$ conda-pack 1>&2

Proof:

(myenv) $ (conda-pack 1>&2) > stdout 2> stderr
(myenv) $ ls -l stdout stderr
-rw-rw-r-- 1 hb hb 18835 Apr 14 12:49 stderr
-rw-rw-r-- 1 hb hb     0 Apr 14 12:48 stdout

@kenodegard
Copy link
Contributor

kenodegard commented Apr 26, 2022

Smarter applications will also output different things depending on whether output is printed to the terminal or piped/redirected:

Normal behavior

$ git clone [email protected]:conda/conda-pack.git
Cloning into 'conda-pack'...
remote: Enumerating objects: 2010, done.
remote: Counting objects: 100% (521/521), done.
remote: Compressing objects: 100% (202/202), done.
remote: Total 2010 (delta 292), reused 464 (delta 281), pack-reused 1489
Receiving objects: 100% (2010/2010), 849.49 KiB | 404.00 KiB/s, done.
Resolving deltas: 100% (1303/1303), done.

Piped behavior

$ git clone [email protected]:conda/conda-pack.git > stdout 2> stderr
$ cat stdout
$ cat stderr
Cloning into 'conda-pack'...

@kenodegard kenodegard added type::feature request for a new feature or capability source::community catch-all for issues filed by community members pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding labels Apr 26, 2022
@github-actions
Copy link

Hi there, thank you for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue at hand
  2. Comment that the issue is still reproducible and include:
    - What OS and version you reproduced the issue on
    - What steps you followed to reproduce the issue

NOTE: If this issue was closed prematurely, please leave a comment.

Thanks!

@github-actions github-actions bot added the stale [bot] marked as stale due to inactivity label Apr 27, 2023
@HenrikBengtsson
Copy link
Author

HenrikBengtsson commented Apr 27, 2023

- Dear GitHub issue, you have not been forgotten. We are still thinking of you.

@github-actions github-actions bot added stale::recovered [bot] recovered after being marked as stale and removed stale [bot] marked as stale due to inactivity labels Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding source::community catch-all for issues filed by community members stale::recovered [bot] recovered after being marked as stale type::feature request for a new feature or capability
Projects
Status: No status
Development

No branches or pull requests

2 participants