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.