utils.py 664 B

123456789101112131415161718192021222324
  1. # -*- coding: utf-8 -*-
  2. """
  3. plan.utils
  4. ~~~~~~~~~~
  5. Various utilities for Plan.
  6. :copyright: (c) 2014 by Shipeng Feng.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from subprocess import Popen, PIPE
  10. def communicate_process(command, stdin=None, *args, **kwargs):
  11. """Run the command described by command, then interact with process.
  12. :param stdin: the data you want to send to stdin.
  13. :return: a tuple of stdout, stderr and returncode
  14. """
  15. p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, *args, **kwargs)
  16. output, error = p.communicate(stdin)
  17. returncode = p.returncode
  18. return output, error, returncode