Author Topic: Executing an external program- from a macro  (Read 9632 times)

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Executing an external program- from a macro
« on: June 19, 2007, 10:59:52 PM »

I want to execute a program that is external to my Slick Macro.

I've searched through the Slick Macro reference for phrases like execute, process, command, but found nothing suitable.

The external program is manually executed, by double clicking, and produces a text file.
At the moment, I am copying and pasting the contents of the text file into my Slick Macro, but want to eliminate these 2 steps. (I haven't figured out how to read a file with Slick-C, and I haven't worked with C in many years. But it's slowly coming back now)

To eliminate the first step, I need to have my Slick Macro launch the external program.

Can this be done from a Slick macro?

Thanks

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Executing an external program- from a macro
« Reply #1 on: June 20, 2007, 01:06:42 AM »
Yes.  shell() is your friend.  You might also use path_search() to find the full path of an executable.  It comes in handy. :)

Kohei

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: Executing an external program- from a macro
« Reply #2 on: June 20, 2007, 08:12:06 AM »
Also have a look here http://community.slickedit.com/index.php?topic=1594.msg7158#msg7158 for an example.
Instead of _ReloadCurFile you can use e.g. status = edit('+l ' maybe_quote_filename( genfile )); to load the generated file.

HS2

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Executing an external program- from a macro
« Reply #3 on: June 20, 2007, 02:20:51 PM »
Yes.  shell() is your friend.  You might also use path_search() to find the full path of an executable.  It comes in handy. :)

Kohei

Thanks

I wasn't able to make shell work, but Dos() did work.
Shell works for some things, but I have to change directory to where the macro file is located first.
For some reason, the macro file execution takes place in some default directory, not where the macro file is.
This is a bit of a problem, because every person who will use this macro can have the macro file in a different location.

When I use shell to invoke the python interpeter, it returns an error. Python is in mty patch, and can be invoked from the cmd line in any directory on my system. I use it daily, but I cannot invoke it from the shell(). Oddly enough, dos() works.

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Executing an external program- from a macro
« Reply #4 on: June 20, 2007, 02:25:48 PM »
Also have a look here http://community.slickedit.com/index.php?topic=1594.msg7158#msg7158 for an example.
Instead of _ReloadCurFile you can use e.g. status = edit('+l ' maybe_quote_filename( genfile )); to load the generated file.

HS2

Thanks. I"m not actually trying to load the generated file.
I need to get the content of the generated file into the call to preprocess("content from generated file goes here")
I know how to do this, now that I can invoke the external program

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Executing an external program- from a macro
« Reply #5 on: June 20, 2007, 02:35:29 PM »
cappy2112:

Take a look at some example code in explore macro.  shell expects a full path to the executable, so you need to use path_search to get its full path, and pass it to shell.  executing fp explore in the editor's command line will get you there.
« Last Edit: June 20, 2007, 02:39:23 PM by Kohei »

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Executing an external program- from a macro
« Reply #6 on: June 20, 2007, 06:46:11 PM »
cappy2112:

Take a look at some example code in explore macro.  shell expects a full path to the executable, so you need to use path_search to get its full path, and pass it to shell.  executing fp explore in the editor's command line will get you there.


Should calling path_search from the Slick command line work?
When I call it from there, it returns unknown command- like path_search could not be found

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Executing an external program- from a macro
« Reply #7 on: June 20, 2007, 06:53:37 PM »
Quote
Should calling path_search from the Slick command line work?

No.  That does not work in the command line.  It is meant to be used in another Slick-C function or command.

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: Executing an external program- from a macro
« Reply #8 on: June 21, 2007, 01:25:06 AM »
@cappy2112:
Only functions prefixed by the '_command' keyword are integrated into the Slick's command system (after loading the module where they are defined) and can be called from commandline, bound to a key combination, added to a menu or added to a toolbar as a (new) button.
But they can also be called like a normal function from another Slick-C function.

HS2

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Executing an external program- from a macro
« Reply #9 on: June 21, 2007, 01:41:10 AM »
@cappy2112:
Only functions prefixed by the '_command' keyword are integrated into the Slick's command system (after loading the module where they are defined) and can be called from commandline, bound to a key combination, added to a menu or added to a toolbar as a (new) button.
But they can also be called like a normal function from another Slick-C function.

HS2

I've just converted all of my code to a batch macro- (see my latest post)