Sublime Forum

Get output of run_command

#1

I am trying to get output of run_command, the return part or the print part and store it in a variable.

class PhpLinterCommand(sublime_plugin.TextCommand):
    def run(self, edit, saveIt=True):
        view = self.view
        print('This output to be taken and stored in variable or the one beloe return True')
        return True

class otherCommand(sublime_plugin.TextCommand):
    def run(self, edit):
       myvar = self.view.run_command('php_linter')
       print(myvar) # shuold output one of them.
0 Likes

#2

run_command() has no return. If you must pass variables among commands, you can make global variables or put them in view settings.

0 Likes

#3

LIKE:

globalVar = ''
class PhpLinterCommand(sublime_plugin.TextCommand):
    def run(self, edit, saveIt=True):
        view = self.view
        print('This output to be taken and stored in variable or the one beloe return True')
        globalVar = True

class otherCommand(sublime_plugin.TextCommand):
    def run(self, edit):
      self.view.run_command('php_linter')
       print(globalVar) # output True
0 Likes

#4

if you try to modify it, you will need to add global globalVar.

class PhpLinterCommand(sublime_plugin.TextCommand):
    def run(self, edit, saveIt=True):
        global globalVar 
        view = self.view
        print('This output to be taken and stored in variable or the one beloe return True')
        globalVar = True
1 Like