nervosnetwork / ckb-cli

CKB command line interface
MIT License
55 stars 35 forks source link

the successfully executed command has its output redirected to stderr. #558

Closed gpBlockchain closed 1 year ago

gpBlockchain commented 1 year ago
./ckb-cli --version
ckb-cli 1.4.0 (33bd1a1 2023-03-27)
guopenglin@MacBook-Pro-4 0.111.0 % export API_URL=http://127.0.0.1:8115 && cd /Users/guopenglin/WebstormProjects/gp/ckb-py-integration-test/download/0.111.0 && ./ckb-cli tx init --tx-file /tmp/tx.txt > demo.log 2>demo.err.log 
guopenglin@MacBook-Pro-4 0.111.0 % cat demo.log 
guopenglin@MacBook-Pro-4 0.111.0 % cat demo.err.log 
status: success
yangby-cryptape commented 1 year ago

Brief Answer

I suggested that in issue #288.

Details

I could understand your confusion. You must be had a misunderstanding with its literal meaning: "stderr is used for errors only".

In fact, the stderr is used for printing things which are not outputs, so users could use pipes easily.

That is a very traditional practice. There are lots examples in the real world.

For examples:

Both curl and jq are very famous open-source projects, and they are started in different decades. And they both use stdout for outputs and stderr for debug messages.

As a reference, I copied some documentation from jq Manual.

... (Recall that a jq program's output values are always output as JSON texts on stdout.) ... The stderr builtin outputs its input in raw mode to stderr with no additional decoration, not even a newline. ... Causes a debug message based on the input value to be produced. The jq executable wraps the input value with ["DEBUG:", <input-value>] and prints that and a newline on stderr, compactly.

P.S.

Feel free to @ me if you still feel confuse, or please close this issue.