-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathScriptBase.py
More file actions
55 lines (43 loc) · 1.31 KB
/
ScriptBase.py
File metadata and controls
55 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
from __future__ import print_function
import sys
import os
import subprocess
import time
fullScript = os.path.abspath(sys.argv[0])
scriptName = os.path.basename(sys.argv[0])
scriptName = os.path.splitext(scriptName)[0]
jarName = scriptName + '.jar'
toolsFolder = os.path.dirname(fullScript)
fullJarPath = os.path.join(toolsFolder, jarName)
jdkDir = os.path.dirname(toolsFolder)
jdkDir = os.path.join(jdkDir, 'jdk', 'bin', 'java')
try:
subProc = subprocess.Popen([jdkDir, '-jar', fullJarPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# If here, start succeeded
except:
# Start failed, try JAVA_home
try:
javaHome = os.environ['JAVA_HOME']
jdkDir = os.path.join(javaHome, 'bin', 'java')
except:
# No JAVA_HOME, try just running java from path
jdkDir = 'java'
try:
subProc = subprocess.Popen([jdkDir, '-jar', fullJarPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except Exception as e:
# Really error
print('Error Launching Tool: ')
print(e)
exit(1)
# wait 3 seconds, if still open good
count = 0
while subProc.poll() is None:
time.sleep(1)
count = count + 1
if count > 2:
exit(0)
outputStd = subProc.stdout.read()
outputErr = subProc.stderr.read()
print(outputStd.decode('utf-8'))
print(outputErr.decode('utf-8'), file=sys.stderr)