Author Topic: how to run a bash script.  (Read 3163 times)

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
how to run a bash script.
« on: June 11, 2012, 08:42:59 am »
Hi,
I have a requirement of writing a command in slicksdit which i will call through a user defined button.
I want to run a bash script in that command.

Quick help will be highly appreciated.

Thanks
Vineet

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: how to run a bash script.
« Reply #1 on: June 11, 2012, 09:19:32 am »
You should search for 'concurrent_command' in the forums for various examples and/or check the 'Help'.
Good luck, HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: how to run a bash script.
« Reply #2 on: June 11, 2012, 09:43:38 am »
if you can help me more, i am very new and i need to finish it today.

get current opened file path into a variable and run a shell script with that path in as arguments.
please let me know if below code is correct way..

thank you very much.

_command copy_fileid_to_clipboard() name_info(',')
{
   _str buf_name=p_buf_name;
   int temp_view_id;
   int orig_view_id=_create_temp_view(temp_view_id);
   // say('copy_filename_to_clipboard temp_view_id='temp_view_id);
   p_view_id=temp_view_id;
   fileid=buf_name; 
   _insert_text(buf_name);
   copy_to_clipboard();
   p_view_id=orig_view_id;
   _delete_temp_view(temp_view_id);
   message('Filename: ' fileid);
concur_command('\\vineet\pc1.sh 'fieldid,false,true,false, false);
}

 // switchbuf_cd: change current working directory to current file directory
// change current directory to that of the current buffer
_command switchbuf_cd()

{
 _str path=strip_filename(p_buf_name,'n');
   int status=chdir(path,1);
   if (!status) {
      message('Current working is 'path);
   }
   else
   message ('get_message(status)');
}

Thanks
Vineet
« Last Edit: June 11, 2012, 09:55:22 am by vineetvijay12 »

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: how to run a bash script.
« Reply #3 on: June 11, 2012, 10:07:37 am »
Wow - challenging...
Next time you should ask your employer for a bit more time to develop something you have no knowledge about ;)

Hope this (windows) example helps to get the idea:
Code: [Select]
_command void cat () name_info (','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   activate_build ();
   _str cmdline="D:\\Tools\\Unix\\wbin\\cat.exe" :+ " " :+ maybe_quote_filename( p_buf_name ) :+ " 2>&1";
   concur_command (cmdline, true, true, false, false);
}

Edit:
You can also use something like that to avoid hardwired paths:
Code: [Select]
   _str cmdline=get_env( "HOME" ) :+ " " ...
Do you need to change to the directory of the current file ?
(I've seen your code a bit late.)

Good luck, HS2
« Last Edit: June 12, 2012, 06:44:52 am by hs2 »

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: how to run a bash script.
« Reply #4 on: June 11, 2012, 10:55:34 am »
thanks, yes you are correct.
i am giving absolute path.

one more help before passing filepath to bash script as command line argument. i want to escape \ to \\, can you please how to do that.

Thanks
Vineet

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: how to run a bash script.
« Reply #5 on: June 11, 2012, 04:23:42 pm »
This should work:
Code: [Select]
_str fname = stranslate ( maybe_quote_filename( p_buf_name ), "\\\\", "\\", "" );Good luck, HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: how to run a bash script.
« Reply #6 on: June 12, 2012, 05:09:49 am »
Hi,
it is working for me.
Thanks for help..