run_with_path.py 792 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2010 Google Inc. All Rights Reserved.
  4. """Runs program specified in the command line with the substituted PATH.
  5. This script is needed for to support building under Pulse which is unable
  6. to override the existing PATH variable.
  7. """
  8. import os
  9. import subprocess
  10. import sys
  11. SUBST_PATH_ENV_VAR_NAME = "SUBST_PATH"
  12. def main():
  13. if SUBST_PATH_ENV_VAR_NAME in os.environ:
  14. os.environ["PATH"] = os.environ[SUBST_PATH_ENV_VAR_NAME]
  15. exit_code = subprocess.Popen(sys.argv[1:]).wait()
  16. # exit_code is negative (-signal) if the process has been terminated by
  17. # a signal. Returning negative exit code is not portable and so we return
  18. # 100 instead.
  19. if exit_code < 0:
  20. exit_code = 100
  21. sys.exit(exit_code)
  22. if __name__ == "__main__":
  23. main()