SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: hensh on March 20, 2020, 11:06:43 AM

Title: Running shell programs
Post by: hensh on March 20, 2020, 11:06:43 AM
The Slick-C code below will not run. However, if Typora.exe is in my PATH, the commented line below works. Why can't Slick-C find 'C:\Program Files\Typora\Typora.exe'? I've tried numerous variations. What am I missing?

Code: [Select]
#include "slick.sh"

_command void runtypora() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   if (_no_child_windows()) {
      _message_box("No buffer is open");
      return;
   }
   if (_isno_name(p_DocumentName) || p_buf_name == '') {
      _message_box("No buffer is open");
      return;
   }
   save();
   //shell('Typora ' p_buf_name, 'QA');
   shell('C:\Program Files\Typora\Typora.exe ' p_buf_name,'QA');
}
Title: Re: Running shell programs
Post by: Dan on March 20, 2020, 11:09:38 AM
Try putting double quotes around C:\Program Files\Typora\Typora.exe  since there are space in it.

If you had this in a variable you could use _maybe_quote_filename() around it.  You still could, but since you have a constant, it's easy enough to just quote.
Title: Re: Running shell programs
Post by: hensh on March 20, 2020, 02:25:27 PM
This was the first thing I tried.

Code: [Select]
shell("C:\Program Files\Typora\Typora.exe " p_buf_name,'QA');
The macro does not compile and I get a message stating that there is an illegal character with a blinking cursor appearing between the colon and the backslash.
Title: Re: Running shell programs
Post by: Dan on March 20, 2020, 02:33:14 PM
Try this:

shell(_maybe_quote_filename('C:\Program Files\Typora\Typora.exe')' 'p_buf_name,'QA');
Title: Re: Running shell programs
Post by: hensh on March 20, 2020, 02:42:12 PM
Worked like charm. Thank you. Any idea why your suggestion was necessary?
Title: Re: Running shell programs
Post by: Dan on March 20, 2020, 03:36:00 PM
Because I answered you before I had coffee ;)

In Slick-C, like in C++, \ escapes certain characters in a double quoted string.  For example, "\t" is a tab character.  "\P" is invalid.

Using single quoted strings gets around this.  However, when you have a filename with spaces like that, you still need to double quote them most of the time.
Title: Re: Running shell programs
Post by: hensh on March 20, 2020, 06:03:26 PM
 ;D

thanks