| View previous topic :: View next topic |
| Author |
Message |
Mdoremus Power User

Joined: 25 Feb 2005 Posts: 62
|
Posted: Tue Mar 01, 2005 5:46 am Post subject: Noob-Running a shell script from an OOo macro |
|
|
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 |
|
 |
Mdoremus Power User

Joined: 25 Feb 2005 Posts: 62
|
Posted: Tue Mar 01, 2005 7:05 am Post subject: |
|
|
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 |
|
 |
bobharvey Super User

Joined: 23 Apr 2004 Posts: 1075 Location: Lincolnshire
|
Posted: Tue Mar 01, 2005 1:01 pm Post subject: |
|
|
| 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 |
|
 |
Mdoremus Power User

Joined: 25 Feb 2005 Posts: 62
|
Posted: Wed Mar 02, 2005 3:03 am Post subject: |
|
|
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 |
|
 |
|