Author Topic: Read output of external programs  (Read 7214 times)

sjeeva

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Read output of external programs
« on: August 24, 2006, 06:09:50 pm »
Hello there!

I am looking for a way to execute external programs (using dos/shell/execute/etc), capture its output and do on of the following without using temporary files:
1 – write to current buffer (VIM equivalent is r!)
2 – display it in a dialog or message box

Can you guide with this please?

Thanks,
Jeeva

bduncan

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: Read output of external programs
« Reply #1 on: August 25, 2006, 05:54:23 pm »
I'm also interested in knowing how to do this.
In addition, I'd like to know how to pipe the output to the "Output" toolbar.

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 288
Re: Read output of external programs
« Reply #2 on: August 25, 2006, 07:20:07 pm »
I've written wrapper macros like this:
Code: [Select]
_command void ddir () name_info (','VSARG2_EDITORCTL)
{
   activate_build ();
   _str cmdline=get_env ("SYSTEMROOT") "\\system32\\cmd.exe" " /c dir" " 2>&1";
   concur_command (cmdline, false, true, false, false);
   // switch focus to editor
   // activate_edit ();
}
Output is captured into 'Build' toolbar.

HS2
« Last Edit: August 25, 2006, 07:33:50 pm by hs2 »

Mr68360

  • Community Member
  • Posts: 46
  • Hero Points: 3
Re: Read output of external programs
« Reply #3 on: March 27, 2007, 09:58:31 pm »
activate-edit() seems deprecated or missing.  What would be the equivalent command to put concur_command()'s output to the current edit buffer? 

Would putting it in a message box entail capturing the output to a string first?  If so, how does concur_comand()'s output get captured to a string?

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 288
Re: Read output of external programs
« Reply #4 on: March 27, 2007, 10:43:13 pm »
Hi Mr68360,

sorry - activate_edit was/is not a std. command. Forget about it.
See below an example to redirect command output to editor:
Code: [Select]
_command void extcmd2editwin (_str cmdline='')
{
   // set to '0' to feed ext. cmd output (.process buffer) to editor
   set_var ( "def_process_tab_output 0" );
   activate_build ();
   concur_command (cmdline, true, true, false, false);
   // switch focus (back) to edit win (if you want)
   cursor_data();
}
concur_command is executed asynchronously. So it's not a applicable to imm. switch def_process_tab_output back to 1 at the end of the command.

You can do that in a sync'd manner by using Clark's 'Execute Slick macro command from external batch file running as concur_command' trick:
See http://community.slickedit.com/index.php?topic=819.msg4226#msg4226 for the gory details ... ;)

You can also set def_process_tab_output on Slick cmdline.
set-var def-process-tab-output 0

HS2

Mr68360

  • Community Member
  • Posts: 46
  • Hero Points: 3
Re: Read output of external programs
« Reply #5 on: April 03, 2007, 05:50:35 pm »
This discussion brings to mind an enhancement to the build mechanism I'd like to see:  Currently when I do a build, the compiler emits the line numbers for errors, and I then have to use Ctrl-Shift-DownArrow to get to the first error.  When I wrote a macro that does a Ctrl-M followed by a Ctrl-Sh-Down, I don't end up on the first error, because the build is "queued" and the Ctrl-Shft-Down executes too soon.

I would like, after the build, to have the cursor go automatically to the first error.  H2S, is this something that could be addressed with these "capture" techniques?

Also: the parameter explanations for concur_command() are rather cryptic and sparse.  Could you elaborate on

command -
leave_active -
quiet -
uniconize -
addErrorInfo -

Thanks,
Chuck

hs2

  • Senior Community Member
  • Posts: 2737
  • Hero Points: 288
Re: Read output of external programs
« Reply #6 on: April 03, 2007, 07:00:54 pm »
@Mr68360:
There is a '_postbuild_' - callback you can use (with Compile/Build/Rebuild).
This jumps to the first error - quite, unlikely ;) - or to the end/bottom of the build win if no error was found.
Code: [Select]
void _postbuild_first_error_or_end (...)
{
   // say ("proj_name:" arg( 1 ) );
   if ( next_error () )
   {
      bottom_of_build ( );
      cursor_data();
   }
}

You need to add this to your personal macro collection and reload.

HS2

Mr68360

  • Community Member
  • Posts: 46
  • Hero Points: 3
Re: Read output of external programs
« Reply #7 on: April 03, 2007, 07:42:01 pm »
Uh...errors...me???...no...uh...I was writing this macro for a friend... ::) ::)

Mr68360

  • Community Member
  • Posts: 46
  • Hero Points: 3
Re: Read output of external programs
« Reply #8 on: April 03, 2007, 09:46:47 pm »
Is any function _postbuild_xxx called?  I named _postbuild_first_error_or_end _postbuild_foo, and it got called!!  Is this a case where any _postbuild_xxx function always gets called for build/rebuild?

Is there a callback for a post-compile (Shift-F10)? 


Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1292
  • Hero Points: 129
Re: Read output of external programs
« Reply #9 on: April 03, 2007, 10:02:35 pm »
Any macro function prefixed with __postbuild__ will be called, though there is no guarantee the order which they are called (search for call_list function for how callbacks are handled in Slick-C).   The postbuild callback should be coming through anytime vsbuild is invoked by the builds tools.  Some build tools are just simply commands executed in the process buffer (without using vsbuild), and don't get the callbacks for them.  We have feature requests for future versions, were we would like to enable this for any build tools through project properties.