Re: bash script in mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg117918] Re: bash script in mathematica?
- From: mmausr <opngid at gmail.com>
- Date: Mon, 4 Apr 2011 06:30:53 -0400 (EDT)
- References: <in6ki7$2ja$1@smc.vnet.net>
Here is some sample code you might find helpful. This example runs under Windows using the cygwin environment to run the bash script. The RunScript command creates a bash script on the fly containing the command for the script to run. The output of the command run from the bash script is redirected to a temp file and then fed back to Mathematica using the FilePrint command. RunScript[command_, workdir_] := Module[{ script = $TemporaryPrefix <> "\\script",(* Windows temp space *) output = "c:\\cygwin\\tmp\\output",(* Cygwin temp space *) shell = "c:\\cygwin\\bin\\bash.exe "}, Put[OutputForm["#!/bin/bash"], script]; PutAppend[ OutputForm["export PATH=/usr/local/bin:/usr/bin:/bin:$PATH"], script]; PutAppend[OutputForm["cd " <> workdir], script]; PutAppend[OutputForm[command <> " >> " <> output], script]; (* Mma writes DOS style format text files by default *) Run["c:\\cygwin\\bin\\dos2unix " <> script]; Run[shell <> script, String]; FilePrint[output]] Remember to change the paths to reflect how cygwin is installed on your particular machine.