Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg22210] Re: shell commands in notebooks
  • From: "P.J. Hinton" <paulh at>
  • Date: Fri, 18 Feb 2000 02:34:45 -0500 (EST)
  • Organization: "Wolfram Research, Inc."
  • References: <88dnnt$> <88g6ie$>
  • Sender: owner-wri-mathgroup at

On 17 Feb 2000, P.J. Hinton wrote:

> 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]
>   ]

There is a simpler approach than this, I should add.

ReadList["!command", Record, RecordSeparators -> {}]

It works under both Windows and UNIX systems.

Here is an example under Windows:

In[1]:= ReadList["!VER", Record, RecordSeparators -> {}]

Out[1]= {                               }
         Windows 95. [Version 4.00.1111]

Here is an example from Linux.

In[1]:= ReadList["!uname -sr", Record, RecordSeparators -> {}]

Out[1]= {Linux 2.2.5-15}

The reason for the depressed output under Windows is that the VER command
returns its output with a leading newline character.


Windows 95. [Version 4.00.1111]

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

  • Prev by Date: Re: Selecting numbers with all odd digits
  • Next by Date: Re: how ColorOutput works?
  • Previous by thread: Re: shell commands in notebooks
  • Next by thread: LogLogPlot trouble