MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Launch kernel and packages from Mac OS's launchd utility

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111983] Re: Launch kernel and packages from Mac OS's launchd utility
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Mon, 23 Aug 2010 02:38:54 -0400 (EDT)
  • References: <i4o23m$aim$1@smc.vnet.net> <i4r499$jre$1@smc.vnet.net>

On Aug 22, 7:13 am, David Reiss <dbre... at gmail.com> wrote:
> I haven't used launchd, but rather just use crontab -- this way the
> approach (for the project for my consulting client) works on Linux as
> well.  It has worked quite well.
>
> Note that, if you use the -init approach rather than the -run
> approach, you may encounter problems.  if the code is in the init.m
> file and you use -init, then the code may run before other components
> of the Mathematica system are loaded; this can cause  unexpected
> results ( the -init approach is the one I first took, but I then went
> over to the -run method after encountering such issues).  So I
> recommend staying with the -run approach, which ensures that the whole
> system is up and running before your code is executed.
>
> I hope this helps...
>
> --Davidhttp://scientificarts.com/worklife
>
> On Aug 21, 4:17 am, Garapata <warsaw95... at mypacks.net> wrote:
>
> > This question follows up on an earlier one where I needed to find out
> > how to launch the Mathematica kernel and a package from the command
> > line on a Mac.
>
> > (See:http://groups.google.com/group/comp.soft-sys.math.mathematica/brow=
se=
> _...)
>
> > The required syntax for the command line looks something like this:
>
> > /Applications/Mathematica.app/Contents/MacOS/MathKernel -run "<</
> > Path.../myAutoRun.m"
>
> > myAutoRun.m has initialized cells that do some stuff and then quit the
> > kernel.  Works fine.
>
> > For my next step, I'd like to run the kernel and myAutoRun.m from a
> > Mac's "launchd" utility and set it up to launch and run the package at
> > specific intervals automatically without further human participation.
> > Apple created launched to integrate a bunch of UNIX utilities like
> > cron.
> > Ostensibly, one can use it to launch daemons, process, and programs
> > from a launchd "property list", basically an XML file that the system
> > runs at startup.
> > So, following Apple's documentation something like this ought to work:
>
> >   <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
> >  http://www.apple.com/DTDs/PropertyList-1.0.dtd>
> >  <plist version="1.0">
> >  <dict>
> > <key>Label</key>
> > <string>myAutoRun test</string>
> > <key>Program</key>
> > <string>//Applications/Mathematica.app/Contents/MacOS/MathKernel</
> > string>
> > <key>ProgramArguments</key>
> > <array>
> > <string>MathKernel</string>
> > <string>  -run </string>
> > <string>  "<</path/myAutoRun.m"</string>
> > </array>
> > <key>StartIntervall</key>
> >  <integer>3600</integer>
> >  </dict>
> >  </plist>
>
> > The stuff between  <dict> and  </dict> does the specific work.
> > The section:
> > <key>ProgramArguments</key>
> > <array>
> > <string>MathKernel</string>
> > <string>  -run </string>
> > <string>  "<</path/myAutoRun.m"</string>
> > </array>
>
> > identifies what to run (apparently, with launchd one can't put the
> > entire command on a single line like you can from a cmd prompt, hence
> > the array).
>
> > and finally the StartInterval section should launch the kernel and run
> > the package every 3600 seconds (each hour)
>
> > Looks good in theory, but it seems launchd doesn't know what to do
> > with the Mathematica command:
>
> > <string>  "<</path/myAutoRun.m"</string>
>
> > following the -run option.
>
> > I've started trying to use:
>
> > -initfile " file"
>
> > which the documentation mentions, but doesn't discuss in detail (that
> > I've found).  I think it should "execute the  commands in the
> > initialization file, ' file'  during startup".
>
> > Sorry for the long winded explanation.
>
> > Now,  a number of questions.
>
> > Can I get launchd to launch the kernel and run the package?
> > How do I do it?
> > Does a better approach exist?
>
> > If anyone can offer general insight or guidelines for auto running
> > packages and the issues involved, that would help a lot.
>
> > Thanks to all.
>
> > G


I have always had the command line launch included as part of an apple
script. In part this is because I sometimes also run non-Mathematica
applications  that are scriptable and combine everything into one
applescript that then gets launched by launchd.

A shell script as described by Nate should also work fine. I'd
recommend using Lingon to set all this up rather than try and
configure the XML directly.

http://library.wolfram.com/infocenter/MathSource/7590/

Mike


  • Prev by Date: Re: embedding 2D graphic
  • Next by Date: Re: Launch kernel and packages from Mac OS's launchd utility
  • Previous by thread: Re: Launch kernel and packages from Mac OS's launchd utility
  • Next by thread: Re: Launch kernel and packages from Mac OS's launchd utility