blob: 96e4ea7eee188899ff77d019e28b26d605d65810 [file] [log] [blame]
Eric Fiselierdd7a4832015-01-22 18:05:58 +00001"""not.py is a utility for inverting the return code of commands.
2It acts similar to llvm/utils/not.
3ex: python /path/to/not.py ' echo hello
4 echo $? // (prints 1)
5"""
6
7import distutils.spawn
8import subprocess
9import sys
10
11
12def main():
13 argv = list(sys.argv)
14 del argv[0]
15 if len(argv) > 0 and argv[0] == '--crash':
16 del argv[0]
17 expectCrash = True
18 else:
19 expectCrash = False
20 if len(argv) == 0:
21 return 1
22 prog = distutils.spawn.find_executable(argv[0])
23 if prog is None:
24 sys.stderr.write('Failed to find program %s' % argv[0])
25 return 1
26 rc = subprocess.call(argv)
27 if rc < 0:
28 return 0 if expectCrash else 1
29 if expectCrash:
30 return 1
31 return rc == 0
32
33
34if __name__ == '__main__':
35 exit(main())