result from "gsutil cp" is always in stderr, not stdout
Asked Answered
C

2

7

As the title, the results from "gsutil cp" doesn't redirect to stdout, it always redirect to stderr.

As an example : gsutil cp existed_file.txt . > >(tee -a out.log) 2> >(tee -a error.log >&2) . In above command, out.log is empty, and error.log has a successful copy result.

Its behavior is wrong, because if above command is correct, its output should return in out.log, not in error.log.

How can i fix it ?

Camber answered 17/5, 2018 at 8:42 Comment(0)
D
8

gsutil outputs progress / status info to stderr by design, to keep progress/status separated from data that's output to stdout. For example, if you run:

gsutil ls gs://my-bucket > listing 2>&1 log

you will see the bucket listing in the file "listing", and any errors or other status info in the file "log".

While gsutil cp output doesn't generate data (only status), we use the above stderr/stdout division for all commands, so gsutil behaves consistently in this regard for all commands.

Dirichlet answered 17/5, 2018 at 15:50 Comment(0)
R
1

If you want to know if gsutil failed, you can use the special parameter $?. From the documentation:

($?) Expands to the exit status of the most recently executed foreground pipeline.

gsutil cp existed_file.txt .
echo $? # Will display 0 if OK and something else if not OK

Note: with powershell, it will display True or False.

Rattail answered 21/4, 2020 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.