Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1464
| From | mmausr <opngid@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: bash script in mathematica? |
| Date | 2011-04-04 10:30 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <inc6ko$u3$1@smc.vnet.net> (permalink) |
| 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.
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
bash script in mathematica? voo <ozcelikov@gmail.com> - 2011-04-02 07:51 +0000 Re: bash script in mathematica? mmausr <opngid@gmail.com> - 2011-04-04 10:30 +0000
csiph-web