Author Topic: Redirect batch file output to a string array.  (Read 3076 times)

mhalsig

  • Community Member
  • Posts: 13
  • Hero Points: 0
Redirect batch file output to a string array.
« on: August 01, 2019, 09:19:13 pm »
I have a batch file that outputs a list of files. I want to capture this list to an array that can be used in a list box (combo box). Is this even possible?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2815
  • Hero Points: 426
Re: Redirect batch file output to a string array.
« Reply #1 on: September 17, 2019, 02:37:42 pm »
Code: [Select]
#pragma option(strict,on)
#include "slick.sh"
#import "guiopen.e"
#import "main.e"
#import "seltree.e"
#import "stdprocs.e"

_command void select_lines_in_file(_str file_name="") name_info(',')
{
   if (file_name == "") {
      file_name = _OpenDialog("-modal",
                              "Select file",
                              "",                   // Initial Wild Cards
                              def_file_types,       // File Type List
                              OFN_FILEMUSTEXIST);
      if ( file_name =="" ) return;
   }

   temp_view_id := 0;
   orig_view_id := 0;
   status := _open_temp_view(file_name,temp_view_id,orig_view_id,'+d');
   if (status) {
      _message_box(nls("Could not open %s\n\n%s",file_name,get_message(status)));
      return;
   }

   _str allLines[];
   p_window_id=orig_view_id;
   temp_view_id.top();
   temp_view_id.up();
   line := "";
   while (!temp_view_id.down()) {
      temp_view_id.get_line(line);
      allLines :+= line;
   }
   _delete_temp_view(temp_view_id);
   p_window_id=orig_view_id;

   selected_items := select_tree(allLines, caption:"Select lines", sl_flags:SL_ALLOWMULTISELECT|SL_FILENAME|SL_SELECTALL|SL_INVERT);
   if (selected_items == "") {
      return;
   }

   foreach (auto item in selected_items) {
      say("select_lines_in_file H"__LINE__": SELECTED: "item);
   }
 
}

mhalsig

  • Community Member
  • Posts: 13
  • Hero Points: 0
Re: Redirect batch file output to a string array.
« Reply #2 on: October 07, 2019, 10:48:13 pm »
Thank you the method worked great.