Author Topic: Running shell programs  (Read 3623 times)

hensh

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Running shell programs
« 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');
}

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Running shell programs
« Reply #1 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.

hensh

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Running shell programs
« Reply #2 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.

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Running shell programs
« Reply #3 on: March 20, 2020, 02:33:14 PM »
Try this:

shell(_maybe_quote_filename('C:\Program Files\Typora\Typora.exe')' 'p_buf_name,'QA');

hensh

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Running shell programs
« Reply #4 on: March 20, 2020, 02:42:12 PM »
Worked like charm. Thank you. Any idea why your suggestion was necessary?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Running shell programs
« Reply #5 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.

hensh

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Running shell programs
« Reply #6 on: March 20, 2020, 06:03:26 PM »
 ;D

thanks