home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PRELOAD.PAK / RUNTHROU.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.1 KB  |  53 lines

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