Redirecting Command Result to File
Redirect command output and error logs to files for parsing and review.
읽는 시간 1분최근 업데이트: 2달 전
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 option. This is what a command with the option might look like:
--json--jsonugs env list --json
Redirecting a command's result (stdout)
To redirect the result of a command to a file, add to the end of your command. When your command succeeds, its result will be redirected to the file.
1> res.jsonres.jsonRedirecting a command's error output (stderr)
To redirect the error output of a command to a file, add to the end of your command. Any error during the execution of your command will end up in the file.
2> 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 example and are arbitrary names. You may change them to fit your needs.
res.jsonlogs.jsonAlthough the example uses both result piping and error piping at the same time, you may also use only one or the other.
When using piping, no output will be logged on the command line interface.