run_perl.py 886 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2014 The Chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. "This script is used to run a perl script."
  7. import optparse
  8. import subprocess
  9. import sys
  10. parser = optparse.OptionParser()
  11. parser.description = __doc__
  12. parser.add_option('-s', '--script', help='path to a perl script.')
  13. parser.add_option('-i', '--input', help='file passed to stdin.')
  14. parser.add_option('-o', '--output', help='file saved from stdout.')
  15. options, args = parser.parse_args()
  16. if (not options.script or not options.input or not options.output):
  17. parser.error('Must specify arguments for script, input and output.')
  18. sys.exit(1)
  19. with open(options.output, 'w') as fo, open(options.input, 'r') as fi:
  20. subprocess.check_call(['perl', options.script], stdout=fo, stdin=fi)
  21. sys.exit(0)