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: [mg22210] Re: shell commands in notebooks
  • From: "P.J. Hinton" <paulh at wolfram.com>
  • Date: Fri, 18 Feb 2000 02:34:45 -0500 (EST)
  • Organization: "Wolfram Research, Inc."
  • References: <88dnnt$11q@smc.vnet.net> <88g6ie$4o1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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