Short context: Github's gh
client adds ANSI colors to its JSON output, which is nice but makes post process hard. So if you pipe the output, gh makes a slightly different and regularly encoded output, for example:
gh api organizations | cat
prints something like
[{"login":"errfree","id":44,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0","url":"https://api.github.com/orgs/errfree","repos_url":"https://api.github.com/orgs/errfree/repos","events_url":"https://api.github.com/orgs/errfree/events","hooks_url":"https://api.github.com/orgs/errfree/hooks","issues_url":"https://api.github.com/orgs/errfree/issues","members_url":"https://api.github.com/orgs/errfree/members{/member}","public_members_url":"https://api.github.com/orgs/errfree/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/44?v=4","description":null},
However, if I do the same with subprocess via
p = subprocess.run('gh api organizations | cat', shell=True, capture_output=True)
print(p.stdout.decode())
the result is completely different:
Why? And: Is there an option to force the command (in my case gh
) to behave like it would be piped?