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.