Forum Discussion

ddribin's avatar
ddribin
New Contributor
2 years ago

"op run" changes stdout and stderr to not be TTYs when masking

While trying to convert a script from a bunch of op read calls to a single call to op run call, in order to improve performance due to https://1password.community/discussion/145854/op-read-is-pretty-slow-700ms-per-invocation#latest being fairly slow, I noticed that stdout and stderr are no longer TTYs when using op run, with masking enabled (the default). This can change the behavior of some commands. The most common case is to disable colors, but I've seen other subtle changes, too, that had me scratching my head until I figured it out what was going on.

I'm not sure how feasible it is to use TTYs when masking, but could this at least be called out in the https://developer.1password.com/docs/cli/reference/commands/run/ for op run?

Demo:

```
$ cat =tty-check

!/bin/sh

if [ -t 0 ]; then echo "stdin a terminal"; else echo "stdin not a terminal"; fi
if [ -t 1 ]; then echo "stdout a terminal"; else echo "stdout not a terminal"; fi
if [ -t 2 ]; then echo "stderr a terminal"; else echo "stderr not a terminal"; fi

$ tty-check
stdin a terminal
stdout a terminal
stderr a terminal

$ MY_USERNAME=op://private/op-test/username op run -- tty-check
stdin a terminal
stdout not a terminal
stderr not a terminal
```

Note that --no-masking keeps them as TTYs:


$ MY_USERNAME=op://private/op-test/username op run --no-masking -- tty-check
stdin a terminal
stdout a terminal
stderr a terminal

They also stay as TTYs if there are no environment variables with password references:


$ op run -- tty-check
stdin a terminal
stdout a terminal
stderr a terminal


1Password Version: 8.10.32
Extension Version: Not Provided
OS Version: macOS 14.4.1
Browser: Not Provided

No RepliesBe the first to reply