我正在运行一个命令,它在执行期间输出一些代码行,在完成时输出最后一些代码行,但是将它通过管道传输到tee
,以便将该输出复制到文件中,只写入最后几行。
命令为sam build
,典型输出如下所示,但只有最后一部分(结果摘要)写入文件。
典型命令输出
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
文件内容
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
2条答案
按热度按时间pftdvrlh1#
您可以将
stderr
和stdout
从sam build
传递到tee
,如下所示:2izufjch2#
如果要将
stderr
通过管道传输到tee
,则需要在管道....command foo 2>&1 | tee foo.txt
.2>
表示将stderr
定向到&1
stdout
之前将stderr
重定向到stdout