open-simulation-platform / cosim-cli

Command-line interface for libcosim
https://open-simulation-platform.github.io/cosim
Mozilla Public License 2.0
10 stars 4 forks source link

All messages from running the cli is directed to stderr #77

Closed kevinksyTRD closed 4 years ago

kevinksyTRD commented 4 years ago

When trying to retrieve the logging messages using check_output from Python, it returns an empty byte string.

checkout('cosim run xxx')

Using Popen where it is possible to get stdout and stderr separately, all the info and error messages are found in stderr and stdout is empty.

with Popen(args=['cosim', 'run', 'xxx'], shell=True, stdout=PIPE, stderr=PIPE) as proc:
    log = proc.stdout.read()  # Always empty
    err = proc.stderr.read()  # Contains both normal logging and error message

This is a bit confusing when integrating cosim as a command line tool.

kyllingstad commented 4 years ago

This is by design, and it is normal for command-line software to operate in this way. The idea is to separate incidental messages and errors from the actual output of the program by printing them to a separate stream. This is especially important when the output is designed to be machine readable, as is the case with cosim inspect and cosim run --mr-progress, for example.

kevinksyTRD commented 4 years ago

I should have tried --mr-progress option. :) Thanks.