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 ?
The gsutil cp command attempts to name objects in ways that are consistent with the Linux cp command. This means that names are constructed depending on whether you're performing a recursive directory copy or copying individually-named objects, or whether you're copying to an existing or non-existent directory.
gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including: Creating and deleting buckets. Uploading, downloading, and deleting objects.
"gcloud" can create and manage Google Cloud resources while "gsutil" cannot do so. "gsutil" can manipulate buckets, bucket's objects and bucket ACLs on GCS(Google Cloud Storage) while "gcloud" cannot do so.
You cannot create a folder with gsutil on GCS. But you can copy an existing folder with gsutil to GCS.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With