Redirecting Command Result to File
Redirect command output and error logs to files for parsing and review.
Read time 1 minuteLast updated 21 hours ago
When running a command, the output is usually visible through the command line interface. However, it's also possible to pipe the command's result and error logs to files.
Recommendation
In order to have parseable and easy to read content in your files, use your command with the--json--jsonugs env list --json
Redirecting a command's result (stdout)
To redirect the result of a command to a file, add1> res.jsonres.jsonRedirecting a command's error output (stderr)
To redirect the error output of a command to a file, add2> logs.jsonlogs.jsonExample
Here's an example of what a command with stdout and stderr piping might look like:ugs env list --json 1> res.json 2> logs.json
On success, a file named res.json
is generated. Here's an example of what that file might contain
res.json[ { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "projectId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "name": "production", "isDefault": true, "createdAt": "2022-07-27", "updatedAt": "2022-12-22", "archivedAt": null }]
On failure, a file named logs.json
is generated. Here's an example of what that file might contain
logs.json[ { "Message": "You are not logged into any service account. Please login using the 'ugs login' command.", "Type": "Error" }]
Notes
The file names provided as exampleres.jsonlogs.json