def run(self):
si = None
if hasattr(subprocess, "STARTUPINFO"):
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
try:
#si.wShowWindow = subprocess.SW_HIDE # default
envPATH = os.environ['PATH'] + LOCAL_PATH
s = sublime.load_settings("Rekit.sublime-settings")
if s.get('node_dir') and envPATH.find(s.get('node_dir')) == -1:
envPATH = envPATH + os.pathsep + s.get('node_dir')
if s.get('npm_dir') and envPATH.find(s.get('npm_dir')) == -1:
envPATH = envPATH + os.pathsep + s.get('npm_dir')
# https://docs.python.org/2/library/subprocess.html
# Note If specified, env must provide any variables required for the program to execute.
# On Windows, in order to run a side-by-side assembly the specified env **must** include a valid SystemRoot.
envObj = {
'PATH': envPATH,
'SYSTEMROOT': os.environ['SYSTEMROOT']
}
p = subprocess.Popen(self.command, cwd=self.working_dir, env=envObj, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, startupinfo=si)
for line in iter(p.stdout.readline, b''):
line2 = line.decode().strip('\r\n')
# only show output for mocha
if re.search(r'run_test\.js|build\.js', self.command[1]) is not None:
show_rekit_output(line2)
if self.on_done:
self.on_done()
except subprocess.CalledProcessError as e:
# show_rekit_output(str(e))
show_rekit_output('running node failed:')
show_rekit_output(str(e))
sublime.error_message(str(e))
except OSError as e:
if e.errno == 2:
main_thread(sublime.error_message, "Node binary could not be found in PATH\nConsider using the node_dir and npm_dir settings for the Rekit plugin\n\nPATH is: %s" % os.environ['PATH'])
else:
show_rekit_output('running node failed:')
show_rekit_output(str(e))
raise e
except Exception as e:
show_rekit_output('running node failed:')
show_rekit_output(str(e))
评论列表
文章目录