I am trying to run a shell command on a file save. I’m using this script:
var filePath = require("ko/views").current().filePath;
require("ko/shell").run("golint",[filePath]);
However, all I ever get is “ko-shell: child process ended with code -1”. I’ve tried it with “echo” in case the shell couldn’t find “golint” but I get the same result. So, obviously I’m doing this wrong, but I don’t know what.
Eventually, when I get this working, I’d like to try something a bit more complex like this:
var filePath = require("ko/views").current().filePath;
var shell = require("ko/shell");
shell._showOutputInHud(shell.run("golint",[filePath]), "Go Lint");
var shell = require('ko/shell');
var commandname = "blah blah shell command";
var process = shell.exec(commandname, {});
process.stdout.on('data', function(data){
// do something
});
The command in my case was just building up some Git stuff, and then in my event handler I parse it an update the UI.
Thanks @neurobashing. How do you update the UI in your “do something”?
With the suggestion from @nathanr, this is what I have now:
var view = require('ko/views').current();
if (view.language === 'Go') {
var filePath = view.filePath;
require('ko/shell').exec('golint', [filePath], {runIn: 'hud'});
}
However, I still don’t see anything. I think I’m confused by what is meant by the “hud”. I would expect to see something appear in maybe the Command Output. Perhaps I’m misunderstanding what the “hud” is.