Sublime Forum

Exit code of 'run_command'

#1

Hey there,

I’m wondering if it’s possible to get the exit code of a command started with ‘run_command’ like the following:

self.view.window().run_command("exec", {
      "cmd": [command],
      "shell": True,
      "working_dir": working_dir
})

I’m running my tests with this command and trying to find a way to tell, if they ran successfully or not. I want to display the panel with the test output only if the tests were failing.

Cheers,

Sebastian

0 Likes

run_command return code
#2

Ok, I’ve figured it out myself. The sad thing is, that all params are converted to JSON, which makes it impossible to pass a method / lambda as callback. Now I have just added a few lines to the ‘on_finished’ callback of ‘ExecCommand’ in ‘Packages/Default/exec.py’. This works for me now, but it makes it impossible to publish such functionality as a plugin. I was trying to reopen the ‘ExecCommand’ class like in ruby, but this is apparently not possible :smile:

Any other ideas how I could inject my needed functionality into the ‘ExecCommand’ class?

Thanks,

Sebastian

0 Likes

#3

Current versions of the exec command do print the exit code if it’s non-zero.

With respect to editing the default exec command, you’d need to make a new command, either by copying it or subclassing from it, and then make your build system use your my_exec command via the target property in the build system.

0 Likes

#4

I want to show the test panel automatically if the tests were failing. So I reckon, that this is not possible with the current implementation of ‘exec’.

Of course, subclassing. Thought for some weird reason, that it wouldn’t be possible, as it’s some kind of default system functionality. Will try it.

Thanks for your Support!

Sebastian

0 Likes

#5

How can you subclass from a class that is in the Default directory?

0 Likes