[platform] passes the PID to watch for to the restarter script (IDEA-162263)
[idea/community.git] / bin / linux / restart.py
1 #!/usr/bin/env python
2
3 # Waits for the parent process to terminate, then executes specified commands.
4
5 import os
6 import sys
7 import time
8
9 if len(sys.argv) < 3:
10     raise Exception('usage: restart.py <pid> <path> [optional command]')
11
12 pid = int(sys.argv[1])
13 while os.getppid() == pid:
14     time.sleep(0.5)
15
16 if len(sys.argv) > 3:
17     os.spawnv(os.P_WAIT, sys.argv[3], sys.argv[3:])
18
19 to_launch = sys.argv[2]
20 if sys.platform == 'darwin':
21     os.execv('/usr/bin/open', ['/usr/bin/open', to_launch])
22 else:
23     os.execv(to_launch, [to_launch])