Capturing the output from a system command into a single string

  • Follow


I am running rexx on a Linux based system. I want to catch the output 
from a system command into a variable.

For example, if I run the tput command as follows, this outputs the 
width of the terminal window:

'tput cols'

I don't want the number 80 to echo to the screen, but instead I want 
that value to be captured into a variable, in a similar manner to how
the Unix shell does this:

WIDTH=`tput cols`

What is the simplest way to achieve this in Rexx?

0
Reply Jonathan 10/11/2010 9:47:19 PM

On Mon, 11 Oct 2010 22:47:19 +0100, Jonathan Hobley wrote:

> I am running rexx on a Linux based system. I want to catch the output
> from a system command into a variable.
> 
> For example, if I run the tput command as follows, this outputs the
> width of the terminal window:
> 
> 'tput cols'
> 
> I don't want the number 80 to echo to the screen, but instead I want
> that value to be captured into a variable, in a similar manner to how
> the Unix shell does this:
> 
> WIDTH=`tput cols`
> 
> What is the simplest way to achieve this in Rexx?

With Regina, you have a couple of options:

cols = 'tput'( 'cols' )
Say 'cols is:' cols

or

Address System 'tput cols' With Output Stem cols.
Say 'cols is:' cols.1
0
Reply Mark 10/11/2010 10:22:27 PM


in 52954 20101011 224719 <Jonathan Hobley> wrote:
>I am running rexx on a Linux based system. I want to catch the output
>from a system command into a variable.
>
>For example, if I run the tput command as follows, this outputs the
>width of the terminal window:
>
>'tput cols'
>
>I don't want the number 80 to echo to the screen, but instead I want
>that value to be captured into a variable, in a similar manner to how
>the Unix shell does this:
>
>WIDTH=`tput cols`
>
>What is the simplest way to achieve this in Rexx?

I use:
'tput lines | rxqueue'
pull lines
0
Reply Bob 10/12/2010 7:42:15 AM

Jonathan Hobley wrote:
> I am running rexx on a Linux based system. I want to catch the output 
> from a system command into a variable.
> 
> For example, if I run the tput command as follows, this outputs the 
> width of the terminal window:
> 
> 'tput cols'
> 
> I don't want the number 80 to echo to the screen, but instead I want 
> that value to be captured into a variable, in a similar manner to how
> the Unix shell does this:
> 
> WIDTH=`tput cols`
> 
> What is the simplest way to achieve this in Rexx?
> 
The answer depends on *which* Rexx interpreter you're using (Regina, ooRexx, 
whatever) and how portable you want your code to be. If it's for your own 
personal use on your own pc and you'll never share it with anyone, then you 
don't care about portability. If you *might* move it to another environment, 
then you probably should consider the impact of any dependencies.

A subroutine function can be coded to hide all dependencies by intelligently 
determining the optimum solution for whatever environment it is running in, thus 
isolating your code from environment changes.

-- 

Les               (Change Arabic to Roman to email me)
0
Reply LesK 10/12/2010 9:00:35 AM

In article <4cb423b6$0$4865$9a6e19ea@unlimited.newshosting.com>, 5mre20
@tampabay.rr.com says...

> The answer depends on *which* Rexx interpreter you're using (Regina, ooRexx, 
> whatever) and how portable you want your code to be.

My rexx interpreter is brexx. The platform is Linux based. The platform 
will not change, but I could possibly use different interpreters such as 
rexximc or regina-rexx on different machines, so it would be useful if I 
had working solutions for these interpreters too.
0
Reply Jonathan 10/12/2010 5:48:11 PM

On Tue, 12 Oct 2010 18:48:11 +0100, <Jonathan Hobley> wrote:

>I could possibly use different interpreters such as 
>rexximc or regina-rexx on different machines

I would recommend that you implement the mechanism as an external
subroutine or function. That way, if you end up with dozens of
programs using the same mechanism, you only have to re-code it once
when you change interpreter.

I have such a command() function in my Object REXX subroutine library.
This is the Windows version:

  ::Routine Command public 
  Parse arg command
  File = env('TEMP')'\command'right(time('L'),6)random(0,99999)'.tmp' 
  Command '>'file '2>&1'
  Line. = records(file)
  Line.0rc = rc
  If rc <> 0 then Line.0cmd = command
  Call SysFileDelete file
  Return line.

It uses my records() function to read the temporary file containing
the STDOUT/STDERR from the command. The output lines are returned in a
stem, with the 0rc and 0cmd tails returning the return code, and the
actual command issued (if it returns a non-zero RC)

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Swifty 10/12/2010 7:19:12 PM

Jonathan Hobley wrote:
> In article <4cb423b6$0$4865$9a6e19ea@unlimited.newshosting.com>, 5mre20
> @tampabay.rr.com says...
> 
>> The answer depends on *which* Rexx interpreter you're using (Regina, ooRexx, 
>> whatever) and how portable you want your code to be.
> 
> My rexx interpreter is brexx. The platform is Linux based. The platform 
> will not change, but I could possibly use different interpreters such as 
> rexximc or regina-rexx on different machines, so it would be useful if I 
> had working solutions for these interpreters too.

If you're going to be doing compatibility testing of your code with different 
interpreters then you should throw ooRexx in to the mix.

-- 

Les               (Change Arabic to Roman to email me)
0
Reply LesK 10/12/2010 11:14:11 PM

In <4cb38e23$0$29989$c3e8da3$5496439d@news.astraweb.com>, on
10/11/2010
   at 10:22 PM, Mark Hessling <mark@rexx.org> said:

>cols = 'tput'( 'cols' )
>Say 'cols is:' cols

>or

>Address System 'tput cols' With Output Stem cols.
>Say 'cols is:' cols.1

The second has the advantage of being ANSI compliant.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 10/13/2010 11:15:45 AM

On Oct 11, 4:47=A0pm, <Jonathan Hobley> wrote:
> I am running rexx on a Linux based system. I want to catch the output
> from a system command into a variable.
>
> For example, if I run the tput command as follows, this outputs the
> width of the terminal window:
>
> 'tput cols'
>
> I don't want the number 80 to echo to the screen, but instead I want
> that value to be captured into a variable, in a similar manner to how
> the Unix shell does this:
>
> WIDTH=3D`tput cols`
>
> What is the simplest way to achieve this in Rexx?

This is not answering your general question, but for the specific
query
about the width of your terminal/screen/window ...

For CMS, TSO, R4, and PC/REXX, you can just simply use the  LINESIZE
bif.   For Regina (under DOS or Windows), I coded an external REXX
subroutine that finds the width via the (DOS)     MODE  CON:
command,  it simply just finds the appropriate output from the  MODE
command to parse.    I also wrote a   SCRSIZE   external REXX
subroutine for those REXXs that didn't support that bif.

I can't understand why Regina hasn't added the  LINESIZE  and
SCRSIZE  bifs, especially since they were in CMS REXX from its
inception.

_______________________________________________ Gerard Schildberger


0
Reply GerardS 10/13/2010 4:47:20 PM

GerardS wrote:
> On Oct 11, 4:47 pm, <Jonathan Hobley> wrote:
>> I am running rexx on a Linux based system. I want to catch the output
>> from a system command into a variable.
>>
>> For example, if I run the tput command as follows, this outputs the
>> width of the terminal window:
>>
>> 'tput cols'
>>
>> I don't want the number 80 to echo to the screen, but instead I want
>> that value to be captured into a variable, in a similar manner to how
>> the Unix shell does this:
>>
>> WIDTH=`tput cols`
>>
>> What is the simplest way to achieve this in Rexx?
> 
> This is not answering your general question, but for the specific
> query
> about the width of your terminal/screen/window ...
> 
> For CMS, TSO, R4, and PC/REXX, you can just simply use the  LINESIZE
> bif.   For Regina (under DOS or Windows), I coded an external REXX
> subroutine that finds the width via the (DOS)     MODE  CON:
> command,  it simply just finds the appropriate output from the  MODE
> command to parse.    I also wrote a   SCRSIZE   external REXX
> subroutine for those REXXs that didn't support that bif.
> 
> I can't understand why Regina hasn't added the  LINESIZE  and
> SCRSIZE  bifs, especially since they were in CMS REXX from its
> inception.
> 
> _______________________________________________ Gerard Schildberger
> 
> 
Because they are CMS specific and not part of the ANSI standard. TSO picked them 
up for consistency and the others followed along before the ANSI standard was 
approved, I suspect.

In the modern age of pc's, both settings are dynamic and fairly meaningless 
UNLESS you know you have a fixed font, such as when using THE editor.	

-- 

Les               (Change Arabic to Roman to email me)
0
Reply LesK 10/13/2010 9:12:37 PM

On Oct 13, 4:12=A0pm, LesK <5mr...@tampabay.rr.com> wrote:
> GerardS wrote:
> > On Oct 11, 4:47 pm, <Jonathan Hobley> wrote:
> >> I am running rexx on a Linux based system. I want to catch the output
> >> from a system command into a variable.
>
> >> For example, if I run the tput command as follows, this outputs the
> >> width of the terminal window:
>
> >> 'tput cols'
>
> >> I don't want the number 80 to echo to the screen, but instead I want
> >> that value to be captured into a variable, in a similar manner to how
> >> the Unix shell does this:
>
> >> WIDTH=3D`tput cols`
>
> >> What is the simplest way to achieve this in Rexx?
>
> > This is not answering your general question, but for the specific
> > query
> > about the width of your terminal/screen/window ...
>
> > For CMS, TSO, R4, and PC/REXX, you can just simply use the =A0LINESIZE
> > bif. =A0 For Regina (under DOS or Windows), I coded an external REXX
> > subroutine that finds the width via the (DOS) =A0 =A0 MODE =A0CON:
> > command, =A0it simply just finds the appropriate output from the =A0MOD=
E
> > command to parse. =A0 =A0I also wrote a =A0 SCRSIZE =A0 external REXX
> > subroutine for those REXXs that didn't support that bif.
>
> > I can't understand why Regina hasn't added the =A0LINESIZE =A0and
> > SCRSIZE =A0bifs, especially since they were in CMS REXX from its
> > inception.
>
> > _______________________________________________ Gerard Schildberger
>
> Because they are CMS specific and not part of the ANSI standard. TSO pick=
ed them
> up for consistency and the others followed along before the ANSI standard=
 was
> approved, I suspect.
>
> In the modern age of pc's, both settings are dynamic and fairly meaningle=
ss
> UNLESS you know you have a fixed font, such as when using THE editor. =A0
>
> --
>
> Les =A0 =A0 =A0 =A0 =A0 =A0 =A0 (Change Arabic to Roman to email me)- Hid=
e quoted text -
>
> - Show quoted text -

I use  LINESIZE  a lot as I like to know how wide the screen is for
many routines/functions:  plotting, histograms (vertical and
horizontal), showing the states of the game "Towers of Hanoi",
showing tables, centering text, how many columns to build when
constructing columner data, when right-justifying or right-
aligning text, and many others.  The DOS prompt window I use under
Windows doesn't change dynamically, but I do have several versions
of the DOS prompt window(s).  I normally use a  50x80  column window,
but also use a  79x184  as well.   I found that PC/REXX will only
support a max of 50x80,  so when the  79x184  screen is used,
something shrinks the screen to  50x80  for the duration of the
output being shown  (and then, most of the time, it re-expands to
the original size, making a very annoying flickering effect.  I
use the  SCRSIZE   subroutine to find the width and depth of the
screen and calculate how much of the screen is useable (say) for
plotting and all that other cra... er stuff mentioned above.
Regina and R4 have no problem with most sizes (as far as I can
tell), but the latest  KEDIT  has a maximum of  120x200.

I never use anything except a fixed font, otherwise plots, tables,
histograms and the like are an exercise in futility.

I haven't used CMS for about twenty years, and yet I still find a
use for  LINESIZE  (and  SCRSIZE)  all the time.

__________________________________________ Gerard Schildberger

0
Reply GerardS 10/21/2010 4:50:08 AM

10 Replies
412 Views

(page loaded in 0.108 seconds)

Similiar Articles:













7/22/2012 10:43:40 PM


Reply: