home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e031 / 3.ddi / MATHZIP2 / STARTUP / RUNTHROU.M < prev    next >
Encoding:
Text File  |  1991-06-19  |  1.2 KB  |  52 lines

  1. (*
  2.  * RunThrough routes an expression through a command and returns the
  3.  * result.  Optional arguments go to the Open command (e.g., to set the
  4.  * GraphicsRendering).
  5.  *
  6.  * (bruce 12 Oct 90 -- modified for 2.0)
  7.  *)
  8.  
  9.  
  10. RunThrough::usage = "RunThrough[\"command\", expr] executes an external
  11. command, giving the printed form of expr as input, and taking the output,
  12. reading it as Mathematica input, and returning the result."
  13.  
  14. (*
  15.  * Externally visible objects: RunThrough
  16.  *)
  17.  
  18. Begin["`Private`"]
  19.  
  20. (*
  21.  * StreamFileName[stream] returns the filename part of a stream indicator,
  22.  * and works in either 1.2 or 2.0. (bruce 17 Sep 90)
  23.  *)
  24.  
  25. StreamFileName[streamhead_Symbol[name_String, serialnumber_Integer]] := name
  26.  
  27. StreamFileName[name_String] := name
  28.  
  29. RunThrough[cmd_String, expr_] :=
  30.     Block[{
  31.         `exprfile = OpenTemporary[],
  32.         `resfile  = OpenTemporary[],
  33.         `tresult
  34.         },
  35.         Write[exprfile, expr];
  36.         (* Write[exprfile, "\n"]; *)
  37.         Close[exprfile];
  38.         Close[resfile];
  39.  
  40.         Run[StringJoin[cmd," < ", exprfile[[1]], " > ",resfile[[1]]]];
  41.         tresult = Get[resfile[[1]]];
  42.         Run[StringJoin["del ",exprfile[[1]]]] ;
  43.         Run[StringJoin["del ",resfile[[1]]]] ;
  44.         tresult
  45.     ]
  46.  
  47. End[]
  48.  
  49. Protect[RunThrough]
  50.  
  51. Null
  52.