shell tee未将所有命令输出重定向到文件

huangapple go评论89阅读模式
英文:

shell tee not redirecting all command output to file

问题

Typical command output

  1. sh-4.2# sam build | tee build.txt
  2. Building codeuri: /var/task/lambda-functions/scaffold-site-codebase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ScaffoldSiteCodebaseFunction
  3. Running NodejsNpmBuilder:NpmPack
  4. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  5. Running NodejsNpmBuilder:CopySource
  6. Running NodejsNpmBuilder:NpmInstall
  7. Running NodejsNpmBuilder:CleanUpNpmrc
  8. Running NodejsNpmBuilder:LockfileCleanUp
  9. Building codeuri: /var/task/lambda-functions/confirm-new-purchase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ConfirmNewPurchaseFunction
  10. Running NodejsNpmBuilder:NpmPack
  11. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  12. Running NodejsNpmBuilder:CopySource
  13. Running NodejsNpmBuilder:NpmInstall
  14. Running NodejsNpmBuilder:CleanUpNpmrc
  15. Running NodejsNpmBuilder:LockfileCleanUp
  16. Building codeuri: /var/task/lambda-functions/register-new-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: RegisterNewCustomerFunction
  17. Running NodejsNpmBuilder:NpmPack
  18. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  19. Running NodejsNpmBuilder:CopySource
  20. Running NodejsNpmBuilder:NpmInstall
  21. Running NodejsNpmBuilder:CleanUpNpmrc
  22. Running NodejsNpmBuilder:LockfileCleanUp
  23. Building codeuri: /var/task/lambda-functions/send-new-purchase-emails runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendNewPurchaseEmailsFunction
  24. Running NodejsNpmBuilder:NpmPack
  25. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  26. Running NodejsNpmBuilder:CopySource
  27. Running NodejsNpmBuilder:NpmInstall
  28. Running NodejsNpmBuilder:CleanUpNpmrc
  29. Running NodejsNpmBuilder:LockfileCleanUp
  30. Building codeuri: /var/task/lambda-functions/send-failed-subscription-renewal-email runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendFailedSubscriptionRenewalEmailFunction
  31. Running NodejsNpmBuilder:NpmPack
  32. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  33. Running NodejsNpmBuilder:CopySource
  34. Running NodejsNpmBuilder:NpmInstall
  35. Running NodejsNpmBuilder:CleanUpNpmrc
  36. Running NodejsNpmBuilder:LockfileCleanUp
  37. Building codeuri: /var/task/lambda-functions/create-stripe-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: CreateStripeCustomerFunction
  38. Running NodejsNpmBuilder:NpmPack
  39. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  40. Running NodejsNpmBuilder:CopySource
  41. Running NodejsNpmBuilder:NpmInstall
  42. Running NodejsNpmBuilder:CleanUpNpmrc
  43. Running NodejsNpmBuilder:LockfileCleanUp
  44. Build Succeeded
  45. Built Artifacts : .aws-sam/build
  46. Built Template : .aws-sam/build/template.yaml
  47. Commands you can use next
  48. =========================
  49. [*] Validate SAM template: sam validate
  50. [*] Invoke Function: sam local invoke
  51. [*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
  52. [*] Deploy: sam deploy --guided

file content

  1. Build Succeeded
  2. Built Artifacts : .aws-sam/build
  3. Built Template : .aws-sam/build/template.yaml
  4. Commands you can use next
  5. =========================
  6. [*] Validate SAM template: sam validate
  7. [*] Invoke Function: sam local invoke
  8. [*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
  9. [*] 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

  1. sh-4.2# sam build | tee build.txt
  2. Building codeuri: /var/task/lambda-functions/scaffold-site-codebase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ScaffoldSiteCodebaseFunction
  3. Running NodejsNpmBuilder:NpmPack
  4. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  5. Running NodejsNpmBuilder:CopySource
  6. Running NodejsNpmBuilder:NpmInstall
  7. Running NodejsNpmBuilder:CleanUpNpmrc
  8. Running NodejsNpmBuilder:LockfileCleanUp
  9. Building codeuri: /var/task/lambda-functions/confirm-new-purchase runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ConfirmNewPurchaseFunction
  10. Running NodejsNpmBuilder:NpmPack
  11. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  12. Running NodejsNpmBuilder:CopySource
  13. Running NodejsNpmBuilder:NpmInstall
  14. Running NodejsNpmBuilder:CleanUpNpmrc
  15. Running NodejsNpmBuilder:LockfileCleanUp
  16. Building codeuri: /var/task/lambda-functions/register-new-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: RegisterNewCustomerFunction
  17. Running NodejsNpmBuilder:NpmPack
  18. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  19. Running NodejsNpmBuilder:CopySource
  20. Running NodejsNpmBuilder:NpmInstall
  21. Running NodejsNpmBuilder:CleanUpNpmrc
  22. Running NodejsNpmBuilder:LockfileCleanUp
  23. Building codeuri: /var/task/lambda-functions/send-new-purchase-emails runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendNewPurchaseEmailsFunction
  24. Running NodejsNpmBuilder:NpmPack
  25. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  26. Running NodejsNpmBuilder:CopySource
  27. Running NodejsNpmBuilder:NpmInstall
  28. Running NodejsNpmBuilder:CleanUpNpmrc
  29. Running NodejsNpmBuilder:LockfileCleanUp
  30. Building codeuri: /var/task/lambda-functions/send-failed-subscription-renewal-email runtime: nodejs18.x metadata: {} architecture: x86_64 functions: SendFailedSubscriptionRenewalEmailFunction
  31. Running NodejsNpmBuilder:NpmPack
  32. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  33. Running NodejsNpmBuilder:CopySource
  34. Running NodejsNpmBuilder:NpmInstall
  35. Running NodejsNpmBuilder:CleanUpNpmrc
  36. Running NodejsNpmBuilder:LockfileCleanUp
  37. Building codeuri: /var/task/lambda-functions/create-stripe-customer runtime: nodejs18.x metadata: {} architecture: x86_64 functions: CreateStripeCustomerFunction
  38. Running NodejsNpmBuilder:NpmPack
  39. Running NodejsNpmBuilder:CopyNpmrcAndLockfile
  40. Running NodejsNpmBuilder:CopySource
  41. Running NodejsNpmBuilder:NpmInstall
  42. Running NodejsNpmBuilder:CleanUpNpmrc
  43. Running NodejsNpmBuilder:LockfileCleanUp
  44. Build Succeeded
  45. Built Artifacts : .aws-sam/build
  46. Built Template : .aws-sam/build/template.yaml
  47. Commands you can use next
  48. =========================
  49. [*] Validate SAM template: sam validate
  50. [*] Invoke Function: sam local invoke
  51. [*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
  52. [*] Deploy: sam deploy --guided

file content

  1. Build Succeeded
  2. Built Artifacts : .aws-sam/build
  3. Built Template : .aws-sam/build/template.yaml
  4. Commands you can use next
  5. =========================
  6. [*] Validate SAM template: sam validate
  7. [*] Invoke Function: sam local invoke
  8. [*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
  9. [*] Deploy: sam deploy --guided

答案1

得分: 1

You can pass both stderr and stdout from sam build to tee like this:

  1. sam build 2>&1 | tee build.txt
英文:

You can pass both stderr and stdout from sam build to tee like this:

  1. 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

huangapple
  • 本文由 发表于 2023年3月9日 17:32:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定