ActiveState Community

Send `command output` to an edit window

Posted by programmer.py on 2008-03-19 08:54
OS: All / Any

Hi all. I'm a new Komodo Edit user.

Is there an easy way to have a command send it's output into an "edit" window instead of the "Command Output" tab?

Currently, I cut/paste into a new window, but thats awkward and clumsy.

Thanks!
jw

toddw | Wed, 2008-03-19 09:23

Hi jw,

Yes, it is possible. When you use the "Tools->Run Command" menu (or create a run command in the toolbox), a dialog will be shown for setting the details. Enabling the "Insert Output" option will redirect the command output into the current editor.

Cheers,
Todd

programmer.py | Wed, 2008-03-19 13:18

Thanks! I saw that, but was hoping there was some trick to "create a temporary file". But this is no big deal.

Thanks a bunch!
jw

toddw | Wed, 2008-03-19 13:52

You could also do this with either a Python or JavaScript macro, something like this (JavaScript version):

var runSvc = Components.classes["@activestate.com/koRunService;1"].
                createInstance(Components.interfaces.koIRunService);
var process = runSvc.RunAndNotify("ls -la" /* command */,
                                  "/home/toddw"  /* cwd */,
                                  "" /* environment settings */,
                                  "" /* stdin input */);
var retval = process.wait(-1); /* wait till the process is done */
if (retval == 0) {
    var newView = ko.views.manager.doNewView("Text", 'editor');
    newView.scimoz.text = process.getStdout();
}
var runSvc = Components.classes["@activestate.com/koRunService;1"].
                createInstance(Components.interfaces.koIRunService);
var process = runSvc.RunAndNotify("ls -la" /* command */,
                                  "/home/toddw"  /* cwd */,
                                  "" /* environment settings */,
                                  "" /* stdin input */);
var retval = process.wait(-1); /* wait till the process is done */
if (retval == 0) {
    var newView = ko.views.manager.doNewView("Text", 'editor');
    newView.scimoz.text = process.getStdout();
}

If you create a JavaScript macro in your Komodo toolbox with this code, then it should provide you with what you need.

Cheers,
Todd

stan | Thu, 2008-03-20 09:10

I am doing quite a lot of macro development these days and the code above was very helpful in my Optimise JavaScript extension. Many thanks for pointing out RunAndNotify. I was using a slightly modified version of Run_RunEncodedCommand, but what you have above is far better.

However, I found something very strange. I am running Windows XP SP 2 and Komodo Edit, version 4.3.0, build 1077. Calling getStdout on the process handle immediately after wait(-1) returns an empty string. If I put this in window.setTimeout(…, 1) then everything seems to be working. This is not an issue for me, but may be something worth looking into.

toddw | Wed, 2008-06-18 12:49

Thanks for the update Stan, I've logged this as a bug here (note: bug was fixed for Komodo 5.0):
http://bugs.activestate.com/show_bug.cgi?id=78030

Cheers,
Todd

programmer.py | Thu, 2008-03-20 06:03

Wow. That's pretty cool.

Thanks a bunch!
jw