MathGroup Archive 2000

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

Search the Archive

Re: shell commands in notebooks


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.

C:\WINDOWS\TEMP>VER

Windows 95. [Version 4.00.1111]


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