Skip to content

Instantly share code, notes, and snippets.

@unlight
Created August 18, 2013 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unlight/6262932 to your computer and use it in GitHub Desktop.
Save unlight/6262932 to your computer and use it in GitHub Desktop.
Hello from Node.js
process.stdout.write("Hello from nodejs.");
import sublime
import sublime_plugin
import os
import subprocess
PLUGIN_FOLDER = os.path.dirname(os.path.realpath(__file__))
#view.run_command("hello_node")
class HelloNodeCommand(sublime_plugin.TextCommand):
def run(self, edit):
node = "node"
scriptPath = PLUGIN_FOLDER + "/hello.js"
output = run_process([node, scriptPath]).decode("utf-8");
region = self.view.sel()[0]
pos = region.begin()
self.view.insert(edit, pos, output)
def run_process(args):
cmd = '"' + '" "'.join(args) + '"'
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return subprocess.Popen(cmd, stdout=subprocess.PIPE, startupinfo=startupinfo).communicate()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment