Author Topic: Run external command when saving?  (Read 6870 times)

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Run external command when saving?
« on: February 02, 2009, 04:52:54 PM »
If it possible to get SE2k8 to run an external command, passing in the name of the file being saved as an argument?  If so, how?  I've looked around a bit and haven't been able to find anything that discusses something like this.  I know you can define commands to run when you build but I'm just wondering about when saving.

thnx,
Christoph

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Run external command when saving?
« Reply #1 on: February 03, 2009, 10:24:00 AM »
If it possible to get SE2k8 to run an external command, passing in the name of the file being saved as an argument?  If so, how?  I've looked around a bit and haven't been able to find anything that discusses something like this.  I know you can define commands to run when you build but I'm just wondering about when saving.

thnx,
Christoph

This is untested but something like this should work.  Functions that start with _cbsave get called after a file is saved.

void _cbsave_run_my_cmd(...)
{
   shell('"' :+ 'c:/temp/some-command.exe" ' :+
               '"' p_buf_name '" ', 'QPA');
}

Also, have a look at the save_file function in saveload.e

Graeme

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Run external command when saving?
« Reply #2 on: February 03, 2009, 01:55:36 PM »
This is untested but something like this should work.  Functions that start with _cbsave get called after a file is saved.
void _cbsave_run_my_cmd(...)
{
   shell('"' :+ 'c:/temp/some-command.exe" ' :+
               '"' p_buf_name '" ', 'QPA');
}
Also, have a look at the save_file function in saveload.e

I took a look at saveload.e and I also took a look at some of the other _cbsave functions.  Is there a way to display the output of the external command?

thnx,
Christoph

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Run external command when saving?
« Reply #3 on: February 03, 2009, 04:17:19 PM »
This could be done similar to this example:
Code: [Select]
_command void _cbsave_run_my_cmd() name_info (','VSARG2_EDITORCTL)
{
   activate_build ();
   _str cmdline=<my external command> :+ " " :+ maybe_quote_filename( p_buf_name ) :+ " 2>&1";
   concur_command (cmdline, false, true, false, false);
}
Made it a _command that you can test it on SE cmdline.
HS2

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Run external command when saving?
« Reply #4 on: February 05, 2009, 06:50:59 PM »
This could be done similar to this example:
Code: [Select]
_command void _cbsave_run_my_cmd() name_info (','VSARG2_EDITORCTL)
{
   activate_build ();
   _str cmdline=<my external command> :+ " " :+ maybe_quote_filename( p_buf_name ) :+ " 2>&1";
   concur_command (cmdline, false, true, false, false);
}
Made it a _command that you can test it on SE cmdline.
HS2

Ok, so I saved the above to a file and loaded it as a module.  However, whenever I save a file, nothing perceptible occurs.  What am I missing?

thnx,
Christoph
« Last Edit: February 05, 2009, 06:55:34 PM by Christoph »

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Run external command when saving?
« Reply #5 on: February 05, 2009, 08:22:39 PM »
Oops - seems that the '_command' (and the name_info(...) stuff) was not right.
Please make it a simple function void _cbsave_run_my_cmd(). This should work (tested it 1 min ago).
Good  luck, HS2