Sublime Forum

Open Terminal (CMD) and run command

#1

I wants to do the following:

Open CMD then CD to current file’s directory then php current_file.

cd $file_path & php $file_name

How do I do it ST3? I do have Terminal package installed.

0 Likes

#2

actually i did this… after a lot of trail and error.


import os, sublime_plugin, subprocess

class CmdCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        path, _ = os.path.split(self.view.file_name())
        os.chdir(path)
        filename = os.path.split(self.view.file_name())[1]
        subprocess.Popen("C:\\Windows\\System32\\cmd.exe /K php %s" % filename)
        
0 Likes

#3

Probably you want https://packagecontrol.io/packages/Console%20Exec .

With it, just add "target": "console_exec" in your .sublime-build. The build will be in a new external terminal (cmd under Windows by default).

1 Like