Sublime Forum

Custom build system command output?

#1

I am new to Sublime and Python so this may be a really simple question.

I wrote a custom sublime window command to perform builds using existing running versions of Visual Studio (based on the excellent visual_studio.vim plugin for gvim). Everything works splendidly (well as splendidly as you could expect when you use COM interop). One of the problems I have though is that I can’t pipe the output back to Sublime’s build system file regexp.

My build system is really simple and just calls the plugin.

{ "target": "vs_build_solution", "file_regex": "(...*?)/(([0-9]*)/) : error C[0-9]*:(...*?)", }

The custom command looks like this:

[code]class VsBuildSolution(sublime_plugin.WindowCommand):
def run(self):
dte_build_solution(0, _filename_output, _option_write_before_build)

fp_output = file (_filename_output, 'r')
output_msg = fp_output.read ()
fp_output.close()

sys.stderr.write(output_msg)

pass[/code]

Where _filename_output is, obviously enough, the file name of the Visual Studio output (i.e. the output of the build). I now want to pipe this output back to the Sublime build system but for the life of me I can’t seem to be able to do it. I tried the following and they just end up displaying the information in the Sublime console but no the sublime build results:

sys.stderr.write sys.stdout.write print

Every other build system example I’ve seen just ends up calling a shell command through the use of ‘exec’ so I am a bit stuck here.

0 Likes

Access build results (errors and warnings) from plugin
#2

Basically for a standard build system:

[code]import sublime, sublime_plugin
execcmd = import(“exec”)

class ExampleExecCommand(execcmd.ExecCommand):
def finish(self, *args, **kwargs):
self.append_data(self.proc, “My content to add to build message\n”)
super(ExampleExecCommand, self).finish(*args, **kwargs) [/code]
Now for you, it looks like you don’t execute an external program but use a COM object, so more tweak are probably needed to the standard build system.
Look at “Sublime Text 2\Packages\Default\exec.py” that contains the the build command (ExecCommand).

Maybe the simplest way is to copy the exec.py source into a new one and rewrite it for your need.

0 Likes

#3

Thank you.

By looking at the exec command (excellent suggestion by the way). It turns out that what I want to do is rather simple. The exec command simply pipes its output to the “exec” panel.

self.window.get_output_panel("exec")

When I do the same everything seems to work as intended.

In the long run I should probably follow your advice and copy/customize more of the infrastructure in the exec.py implementation.

1 Like