Sublime Forum

Dump/Pipe contents of build command output from console to file

#1

OSX: 10.11.5
ST3 Build 3114

For a small plugin I am developing right now, I would like to dump or pipe the contents of a command in a build system to a file. The command I tried to use in ST3, works on the command line. I basically tried to use $command > $file and $command | tee $file but both don’t work in ST3 console. Any tips or pointers are appreciated as always!

EDIT: I should say that I use absolute paths for the file locations and that the dump fails silently.

0 Likes

Correct way to use a complicated pipe in build system
#2

Please post your current build system.

0 Likes

#3

There you go:

Contents of the .sublime-build:

{
	"target": "rebuild_wiki",

    "variants": [
    	{ "name": "Run", "refresh": true },
    	{ "name": "ikiwikiEditing: Refresh", "refresh": true },
    	{ "name": "ikiwikiEditing: Refresh and Verbose", "verbose": true ,"refresh": true },
    	{ "name": "ikiwikiEditing: Rebuild", "refresh": false },
    	{ "name": "ikiwikiEditing: Rebuild and Verbose", "verbose": true ,"refresh": false },
    	{ "name": "ikiwikiEditing: Update Tags", "utags": true },
    ]
}

Contents of rebuildwiki.py:

import sublime, sublime_plugin

class RebuildWikiCommand(sublime_plugin.WindowCommand):
	def run(self, verbose=False, refresh=False, utags=False):
		s = sublime.load_settings("ikiwikiMarkdown.sublime-settings")
		setup_file = s.get("ikiwiki_setup_file")
		working_dir = s.get("ikiwiki_working_dir")
		def build_ikicmd():
			ikicmd = "ikiwiki"
			if setup_file:
				ikicmd+=(" --setup " + setup_file)
			else:
				sublime.status_message("Please add setup file in ikiwikiEditing options!")
			if verbose:
				ikicmd+=(" --verbose")
			if refresh:
				ikicmd+=(" --refresh")
			if utags:
				tag_file = s.get("ikiwiki_tag_file")
				completion_file = s.get("ikiwiki_completion_file")
				ikicmd+=(" --render " + tag_file + " > " + completion_file)
   			return ikicmd
		self.window.run_command('exec', {'shell_cmd': build_ikicmd(), 'working_dir': working_dir} )
0 Likes

#4

From reading this, I would assume that replacing " > " + completion_file with ' | tee "{}"'.format(completion_file) would work (note that I enclosed the file path with quotation marks). If it doesn’t, you’ll need to look into what I explained in this other thread:

2 Likes

#5

Thanks, that worked.

0 Likes