aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Do not issue ANSI escapes if stdout is not connected to terminal

Open septatrix opened this issue 7 months ago • 9 comments

Describe the bug

When invoking commands like aws s3 cp from scripts, the program issues ANSI sequences like the one for the progress notification (i.e. move cursor back to start of line). If these scripts not log their output to a file they instead result in a jumbled mess which is hard to read

Regression Issue

  • [ ] Select this option if this issue appears to be a regression.

Expected Behavior

If stdout/stderr is not connected to a terminal the CLI should either a) automatically infer --no-progress, or b) write each progress update on a new line

Current Behavior

Image

The ^M is how less represents these ANSI escapes

Reproduction Steps

aws s3 cp ./foo s3://bar/ >log.txt

Possible Solution

This can be somewhat mitigated by explicitly using --no-progress but doing so obviously hides any progress

Additional Information/Context

No response

CLI version used

awscli2-2.25.0

Environment details (OS name and version, etc.)

Fedora 42

septatrix avatar Jun 02 '25 17:06 septatrix

Hello @septatrix, thanks for reaching out. We are currently working on this/handing proper readable output. We don't have a timeline for now on the release but please ensure to check our changelog for updates moving forward: https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst . Thank you.

adev-code avatar Jun 11 '25 18:06 adev-code

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

github-actions[bot] avatar Jun 21 '25 19:06 github-actions[bot]

Does not seem to be fixed yet

septatrix avatar Jun 25 '25 11:06 septatrix

Also not sure why this is tagged with "response-requested"?

septatrix avatar Jun 25 '25 11:06 septatrix

Retried the command: aws s3 cp ./testfile.bin s3://<bucket-name>/ &> log.txt and aws s3 cp --no-progress ./foo s3://bar/ 2>log.txt and there was no ANSI escape. Are you still seeing the escapes? If so, what is the command to repro?

adev-code avatar Sep 15 '25 22:09 adev-code

I still see them using any of:

aws s3 cp s3://<bucket>/<file> . | less
aws s3 cp s3://<bucket>/<file> . | cat -A
systemd-run --user --unit aws-s3-test --same-dir \
  -E AWS_ACCESS_KEY_ID=... -E AWS_SECRET_ACCESS_KEY=... -E AWS_ENDPOINT_URL=... \
  .venv/bin/aws s3 cp s3://<bucket>/<file> . \
  && journalctl --user --unit aws-s3-test # here it shows up as "aws[<PID>]: [3.7K blob data]"

septatrix avatar Sep 16 '25 19:09 septatrix

Hello @septatrix, from CLI Version2: 2.31.0 :

enhancement:``s3``: Add controls over progress status message frequency and multiline printing

Adding --progress-multiline show progress on multiple lines rather than one line, shown here on s3 cp command.

adev-code avatar Oct 10 '25 20:10 adev-code

That's great, now the only thing missing is to automatically infer that flag when we detect that stdout is not a terminal

septatrix avatar Oct 10 '25 20:10 septatrix

The team has decided to plan for this feature request. We do not have a timeline yet and this issue will remain open for tracking.

adev-code avatar Oct 17 '25 05:10 adev-code