process_cli.py 664 B

123456789101112131415161718192021222324252627
  1. from __future__ import absolute_import, division
  2. import sys
  3. import os
  4. try:
  5. # On Windows, stdout is not opened in binary mode by default,
  6. # so newline characters are munged on writing, interfering with
  7. # the tests.
  8. import msvcrt
  9. msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
  10. except ImportError:
  11. pass
  12. # Loop over each of the arguments given and print it to stdout
  13. for arg in sys.argv[1:]:
  14. res = arg + chr(0)
  15. if sys.version_info < (3, 0):
  16. stdout = sys.stdout
  17. else:
  18. stdout = sys.stdout.buffer
  19. res = res.encode(sys.getfilesystemencoding(), "surrogateescape")
  20. stdout.write(res)
  21. stdout.flush()