open-simulation-platform / cosim-cli

Command-line interface for libcosim

Home Page:https://open-simulation-platform.github.io/cosim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All messages from running the cli is directed to stderr

kevinksyTRD opened this issue · comments

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.

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.

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