OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Noob-Running a shell script from an OOo macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
Mdoremus
Power User
Power User


Joined: 25 Feb 2005
Posts: 62

PostPosted: Tue Mar 01, 2005 5:46 am    Post subject: Noob-Running a shell script from an OOo macro Reply with quote

Hi all,
I need to put a macro so that when it is run it will in turn execute a shell script. I think I have it going in the right direction but am grateful for any help and thoughts. These macros are running 1st on a Sun machine (using Applix) and I want to convert the files over to OOo to run on a linux machine.

*******************************************************************
Old Macro -- Sun
*******************************************************************
Code:

macro synchronize
  var run_schedule
  run_schedule=SHELL_COMMAND@("synchronize.sh &")
endmacro



*******************************************************************
New Macro -- Linux (with OOo)
*******************************************************************
Code:

Sub sync_schedule
  Dim run_schedule
  run_schedule = shell(/pathof/shell_script/synchronize.sh)
End Sub

Again, any help is greatly appreciated to let me know if im going in the right direction or if im WAY off. *Should be noted that these are the first macro's im working with in OOo*
Back to top
View user's profile Send private message
Mdoremus
Power User
Power User


Joined: 25 Feb 2005
Posts: 62

PostPosted: Tue Mar 01, 2005 7:05 am    Post subject: Reply with quote

I've found this on the dev mailing list::::
Quote:

Alle 09:33, sabato 8 maggio 2004, Didier DP ha scritto:
> Hello,
>
> I wrote this macr to launch a program in a terminal under linux:
>
> Sub TryThis
> cheminprog=ConvertToUrl("/home/didier/ooovirg.sh")
> Print FileExists(cheminprog)
> Print cheminprog
> shell(cheminprog)
> End Sub
>
> The path is right but I get an error "file not found"

the Shell funtion requires an executable in the first argument.
(/bin/sh or /bin/bash in your case)

You must pass the script as argument.

Further, I think that you should not use url's with shell function but simply
OS dependent path (as shown in the user guide)


ciao
Paolo


I see essentially what I am doing but I am confused on how to add the /bin/sh or /bin/bash and how the setup would be, since the Help on OOo only gives a window example and im not a linux professional. So I am a little closer I think .....
Back to top
View user's profile Send private message
bobharvey
Super User
Super User


Joined: 23 Apr 2004
Posts: 1075
Location: Lincolnshire

PostPosted: Tue Mar 01, 2005 1:01 pm    Post subject: Reply with quote

Mdoremus wrote:
I see essentially what I am doing but I am confused on how to add the /bin/sh or /bin/bash and how the setup would be, since the Help on OOo only gives a window example and im not a linux professional.


*nix has a wide range of optional command line interpreter or 'shell' programmes, with various programming syntaxes and feature sets. The lowest common denominator is sh, and nearly every linux distro defaults to bash. In most cases the full path to the shell programme is /bin/sh or /bin/bash] The following *nix commands will confirm what is happening on your particular host:

printenv SHELL display user's default shell
which sh
which bash display the path to the shell executable
man sh
man bash display the manual pages

There is nothing to stop you invoking any shell for your call - it need not be the one the user is using. It's only a programme, after all.

All this means is that if you supply "/bin/bash" as the shell parameter, it will almost certainly work over 95% of the time, and "/bin/sh" over 99% of the time. If you want to prgrammatically check that the interpreter exists before you invoke it, that gets more complex but is still quite possible.
Back to top
View user's profile Send private message
Mdoremus
Power User
Power User


Joined: 25 Feb 2005
Posts: 62

PostPosted: Wed Mar 02, 2005 3:03 am    Post subject: Reply with quote

Thank you for the speedy reply I believe I have it set up correctly now. If any of the members with a little more experience care to look and give me a yes or no that would be great.

Code:

Sub sync_schedule
   Dim run_schedule
   run_schedule = Shell("/bin/sh", "/path/to/file.sh", 2)
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group