英文:
shell tee not redirecting all command output to file
问题
Typical command output
sh-4.2# sam build | tee build.txt
Building codeuri: /var/task/lambda-functions/scaffold-site-codebase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ScaffoldSiteCodebaseFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/confirm-new-purchase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ConfirmNewPurchaseFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/register-new-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: RegisterNewCustomerFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/send-new-purchase-emails runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendNewPurchaseEmailsFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/send-failed-subscription-renewal-email runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendFailedSubscriptionRenewalEmailFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/create-stripe-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: CreateStripeCustomerFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
file content
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
英文:
I'm running a command that output some lines of code during execution and some final ones when finished, but piping it to tee
to have that output duplicated to file write just the final lines.
The command is sam build
, and typical ouput is as follows, but only the last section (the result recap) is written to file.
Typical command output
sh-4.2# sam build | tee build.txt
Building codeuri: /var/task/lambda-functions/scaffold-site-codebase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ScaffoldSiteCodebaseFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/confirm-new-purchase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ConfirmNewPurchaseFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/register-new-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: RegisterNewCustomerFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/send-new-purchase-emails runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendNewPurchaseEmailsFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/send-failed-subscription-renewal-email runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendFailedSubscriptionRenewalEmailFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Building codeuri: /var/task/lambda-functions/create-stripe-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: CreateStripeCustomerFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
file content
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
答案1
得分: 1
You can pass both stderr
and stdout
from sam build
to tee
like this:
sam build 2>&1 | tee build.txt
英文:
You can pass both stderr
and stdout
from sam build
to tee
like this:
sam build 2>&1 | tee build.txt
答案2
得分: 0
If you want stderr
to be piped to tee
then you need to redirect stderr
to stdout
before the pipe.... command foo 2>&1 | tee foo.txt
. 2>
represents directing stderr
to &1
stdout
.
英文:
If you want stderr
to be piped to tee
then you need to redirect stderr
to stdout
before the pipe.... command foo 2>&1 | tee foo.txt
. 2>
represents directing stderr
to &1
stdout
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论