Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: shell commands in notebooks

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22186] Re: shell commands in notebooks
  • From: "P.J. Hinton" <paulh at wolfram.com>
  • Date: Thu, 17 Feb 2000 01:24:21 -0500 (EST)
  • Organization: "Wolfram Research, Inc."
  • References: <88dnnt$11q@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 16 Feb 2000, Wolfgang Schadow wrote:

> How can I execute shell commands from within a notebook? The book says
> 
> !date
> 
> or 
> 
> Run["date"]
> 
> This works fine in a terminal session, but not in a notebook. It seems
> that the commands are executed but the output is going somewhere else.
> To see this try
> 
> Run["date > foo"]
> !!foo
> 
> So what's happening with the output? (Mathematica 4.0 under Linux)

Neither the front end nor the kernel captures output (stdout or stderr)
from executables invoked by the kernel.  As a result the output is not
seen.  This is noted in _The Mathematica Book_ (Fourth Edition).  You can
retrieve this section of the documentation through the Help Browser by
executing the following command:

FrontEndExecute[
  FrontEnd`HelpBrowserLookup[
    "MainBook",
    {"2.11.12", "2.14"}
  ]
]

You can capture the output with a funciton like this.

RunCapture[cmd_String, arg__:""] := 
  Module[
    {outfil = Close[OpenTemporary[]], result, stmp}, 
    Run[cmd, arg, ">", outfil];
    stmp = OpenRead[outfil];
    result = Read[outfil, Record, RecordSeparators -> {}];
    Close[stmp]
    DeleteFile[outfil];
    Return[result]
  ]

-- 
P.J. Hinton
Mathematica Programming Group           paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.




  • Prev by Date: Re: How to force saving in .m format?
  • Next by Date: Re: LogLogPlot trouble
  • Previous by thread: shell commands in notebooks
  • Next by thread: Re: shell commands in notebooks