Reputation: 1512
My general question is that, at least for debugging a build file, I would like to see an exact version of the command that is executed. I will give an example below. I would also like to see the output of that execution that gets sent to STDOUT, since ST only captures the output to STDERR.
Here is an example of why I might want this.
I have created the build file sql.sublime_build and saved it in the Sublime Packages Directory.
{ "cmd": ["psql", "-U", "tevs", "-d", "tevs", "-o", "psql_out.txt", "-f", "$file"] }
I have a pane in ST3 open to psql_out.txt so that I will see it reloaded if running build changes its contents.
I have a file testbuild.sql that works if I run psql from the command line with input coming from it.
When I have the ST3 tab open for testbuild.sql and press command-B, I see the ST3 footer line change to "building" for a few seconds, but there is no change in the output file and nothing appears in the bottom pane of the ST3 window that opens up when one types command-B.
It would be very helpful just to see exactly how ST3 is invoking the command.
I would prefer a solution that doesn't involve modifying Sublime Text itself.
PS I have also tried the longer form
{ "cmd": ["psql", "-U", "tevs", "-d", "tevs", "-o", "/Users/Wes/Dropbox/Programming/ElectionTransparency/psql_out.txt", "-f", "$file"], "working_dir" : "/Users/Wes/Dropbox/Programming/ElectionTransparency" ?}
Upvotes: 1
Views: 1029
Reputation: 22791
Handling the parts of your question in order:
I would like to see an exact version of the command that is executed.
As long as your build system does not set the option quiet
to true
, Sublime outputs what it's running to its console when you execute a build system. quiet
defaults to false
, so as long as you're not setting it you will see what it's running. For example:
You can open the console via View > Show Console
from the menu or pressing Ctrl+`
I would also like to see the output of that execution that gets sent to STDOUT, since ST only captures the output to STDERR.
Sublime captures and displays both stdout
and stderr
and displays them in the build results panel. The most common reason for this not doing what you expect is usually related to a program buffering its output, which makes it not appear in the build results until after the program has terminated or generated a whole bunch of output.
Assuming you actually wanted to still generate output to a file and also see it in the build results window, something like the following should work (caveat: I do not use nor am familiar with psql):
{
"shell_cmd": "psql -U tevs -d tevs -f $file | tee psql_out.txt",
"selector": "source.sql"
}
This uses shell_cmd
instead of cmd
, which allows for the use of shell redirection. By not specifying the -o
psql sends its output to stdout
instead (if it does not you would need to set the appropriate argument to get it to do that). The tee
program pipes stdin
to stdout
and also saves it to the list of files you give it, so you can see the output in the terminal and also save it to the file at the same time.
It would also be helpful to get other diagnostic information from ST3 when attempting a build. For example in one iteration of this I has a .sublime_build file with faulty JSON syntax. It would have been great to be told that the JSON didn't parse.
There's no direct way to do this for a build system; if it doesn't parse, it doesn't show up in the build system menu and unlike other such files, Sublime doesn't throw an error. However, the syntax highlighting will give you hints when it thinks the syntax is invalid, so that can help (here the shell_cmd
line is missing a trailing comma so the syntax is mad at the following colon character):
If you're not seeing those sorts of error hints, it might be because the color scheme you're using doesn't handle them.
Upvotes: 2