Author Topic: Help with external_cmd()  (Read 5264 times)

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Help with external_cmd()
« on: November 16, 2007, 02:02:36 PM »
SlickEdit 12.0.3, WinXP

I'm having trouble formatting the command to pass to external_cmd().

I want to launch and external file and pass the current buffer's filename on the cmd line.
I suspect the program path/name needs to be quoted, since it is in 'c:\program files\'.

'\"c:\program files\doit.exe \" :+ p_buf_name '   ???

Any suggestions for how to create the command string?
Thanks.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help with external_cmd()
« Reply #1 on: November 16, 2007, 02:15:20 PM »
This should do:
Code: [Select]
   _str cmdline = "D:\\path\\to\\exe" :+ " " :+ maybe_quote_filename (p_buf_name);
   shell (cmdline,"AP"); // or sth. else
HS2

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Help with external_cmd()
« Reply #2 on: November 16, 2007, 02:43:16 PM »
Thanks, but no joy.

Code: [Select]
_str cmdline = "C:\\Program Files\\XML Notepad 2007\\XmlNotepad.exe" :+ " " :+ maybe_quote_filename (p_buf_name);
 message("Launching " :+ cmdline);
 pushToClipboard(cmdline);
 r = shell (cmdline, "AP"); // or sth. else
 message("Result " :+ r);

Here's the command line, from the clipboard:
C:\Program Files\XML Notepad 2007\XmlNotepad.exe "C:\Program Files\SlickEdit 2007\macros\cbmacros.e"

Nothing is launched; r = -2007.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help with external_cmd()
« Reply #3 on: November 16, 2007, 03:06:12 PM »
Ok - missed to quote the tool filename too:
Code: [Select]
_str cmdline = maybe_quote_filename ("D:\\path\\to\\exe") :+ " " :+ maybe_quote_filename (p_buf_name);
HS2

jbhurst

  • Senior Community Member
  • Posts: 405
  • Hero Points: 33
Re: Help with external_cmd()
« Reply #4 on: November 16, 2007, 05:40:13 PM »
BTW,

Did you know that if you use single quotes for strings you don't need to escape your backslashes? I think this would work too:
Code: [Select]
_str cmdline = maybe_quote_filename ('D:\path\to\exe') :+ " " :+ maybe_quote_filename (p_buf_name);

John Hurst
Wellington, New Zealand

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help with external_cmd()
« Reply #5 on: November 16, 2007, 05:55:19 PM »
John is right - of course. This would make it more readable too.
You'd need double quotes if dealing with strings containing single quotes or you need to single quote the single quote:
Code: [Select]
"'"  // 1 (double quoted) single quote string
'''' // 1 (single quoted) single quote string
My 2ct, HS2