Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SublimeText 3 plugin right click on batch file or directory to run Command Prompt on Windows
import sublime
import sublime_plugin
import os
import subprocess
class Runcmd(sublime_plugin.ApplicationCommand):
def run(self, paths):
print("-- RunCMD --")
if os.path.isdir(paths[0]):
subprocess.Popen(['cmd.exe','/s', '/k', 'pushd', paths[0]]);
# "cmd.exe" /s /k pushd "C:\Users\ndunks\AppData\Roaming\Sublime Text 3\Packages\User"
return True
path = os.path.dirname(os.path.abspath(paths[0]))
pipe = subprocess.Popen(paths[0], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path)
while True:
line = pipe.stdout.readline()
if line:
print( line.decode("ascii").strip('\r\n') )
if not line:
break
return True
def is_visible(self, paths):
if os.path.isdir(paths[0]):
return True
name, ext = os.path.splitext(paths[0])
return ext == '.cmd' or ext == '.bat'
[
{
"caption": "Run Batch",
"command": "runcmd",
"args": {
"paths": []
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.