Q:

Python subprocess/Popen stdout is truncated

The output of the Popen stdout is not the same as running the command from Shell, or using os.system:
cmd = ['git', 'diff', commitHash, '--stat']

print Popen(cmd, stdout=PIPE).stdout.read().strip()
os.system(' '.join(cmd))

The output from Popen:
 src/tech/dalvik/sidebar.md                         |   10 -
 .../encryption/android_crypto_implementation.md    |  359 --
 src/tech/encryption/index.md                       |   22 -
 src/tech/encryption/sidebar.md                     |    9 -
 src/tech/index.md                                  |   58 -
 src/tech/nfc/index.md                              |   25 -
 src/tech/nfc/sidebar.md                            |    7 -
 src/tech/sidebar.md                                |    5 -
 templates/footer                                   |    3 +-
 templates/includes                                 |    2 +-
 templates/sidebar                                  |    2 +-
 257 files changed, 32311 insertions(+), 11358 deletions(-)

The output from os.system (same as running from Shell)
 src/tech/dalvik/sidebar.md                                         |   10 -
 src/tech/encryption/android_crypto_implementation.md               |  359 ---------
 src/tech/encryption/index.md                                       |   22 -
 src/tech/encryption/sidebar.md                                     |    9 -
 src/tech/index.md                                                  |   58 --
 src/tech/nfc/index.md                                              |   25 -
 src/tech/nfc/sidebar.md                                            |    7 -
 src/tech/sidebar.md                                                |    5 -
 templates/footer                                                   |    3 +-
 templates/includes                                                 |    2 +-
 templates/sidebar                                                  |    2 +-
 257 files changed, 32311 insertions(+), 11358 deletions(-)

How can I get subprocess.Popen works just like os.system?
I found a similar question here: Stdout captured from pipe in Python is truncated, but setting the LANG environment variable doesn't seem to work.
Thanks!

A:

I don't think that the output is actually being truncated.
Probably git is giving you different outputs, trying to best present the diff stat to you.
From your example, I guess that the issue is different values for the envvar COLUMNS.
Check how many columns does you terminal have with:
$ echo $COLUMNS
And set this envvar in the Popen call:
Popen(cmd, stdout=PIPE, env={'COLUMNS':'249'})

