Newsgroups: comp.lang.rexx
Path: utzoo!utgpu!watserv1!maytag!watcsc!psop
From: psop@watcsc.waterloo.edu (Paul Sop)
Subject: Re: Single character input
Message-ID: <1990Dec30.222612.4636@watcsc.waterloo.edu>
Reply-To: psop@watcsc.waterloo.edu (Paul Sop)
Organization: University of Waterloo Computer Science Club
References: <1990Dec30.035944.1472@ddsw1.MCS.COM>
Date: Sun, 30 Dec 90 22:26:12 GMT

In article <1990Dec30.035944.1472@ddsw1.MCS.COM> veck@ddsw1.MCS.COM (Steven P. King) writes:
>Rexx question for the peanut gallery.  ARexx, actually.  Is there a way to
>get single character input from the keyboard?  PULL wants a carriage return.
>I'm trying to write a program in which it's pretty vital to have single
>keystroke commands.

No kidding.  The only way I've gotten around this is to hack in a handler
that will append an end of line after every letter the person types.
(It's in a serial handler though)

>And as long as we're on the subject...  Is there some easy way to get the
>output from shell commands into an ARexx program?  I cut my teeth on Rexx
>under VM/CMS, where you could (STACK or (QUEUE the output of most external
>commands, to be read into Rexx by simple PULL statements.  Is there some
>similar mechanism on the Amiga?  Or better, under csh on Unix I can do
>things like "set x = `date`", which executes the "date" command and assigns 
>the output to the variable 'x'.  I'd absolutely LOVE this kind of expansion
>from within ARexx.

Simple.  Very simple.  I wrote a shell in AREXX which lets me do this quite
easily.  I'm in a good mood, so I even went to the trouble of cutting out
the procedure and pasting together an example.

It's pretty much self explanitory:

Procedure:  Shellit
Arguments:  1 Valid DOS command
  Returns:  # of lines of output generated
            -1 if no output lines generated.
 Modifies:  Stem variable "Command"  Command.0 = # of lines of output.
            Command.1 = first line of output, command.2 = 2nd...


Anyway, here's a program which uses the procedure:

/* Shellit.REXX   -PD By Paul Sop- */
/* Runs DOS command and puts output in stem variable command */

options prompt "Shell What? "
parse pull command

say
say "The output for this command is:"
say

if shellit(command) >0 then do i = 1 to command.0
   say command.i
end

exit 0


shellit: procedure expose command.

   /* Shell an argument to DOS but put output in stem variable command. */
   /* Command.0 contains the # of lines of output */

   parse arg command
   lines = 0
	if command ~="" then do
      address command word(command,1) ">t:shellit.tmp" delword(command,1,1)
      if open("shellit", "t:shellit.tmp", "R") then do until eof("shellit")
         lines = lines + 1
         command.lines = readln("shellit")
      end
   end
   command.0 =  lines - 1
   call close "shellit"
return command.0




The output of the program would look like this:

Shell What? ls -l shell*

The output for this command is:

-----rwxd       3      747  Dec 31 05:15  shellit.rexx
-----rwxd       1        0  Dec 31 05:15  shellit.tmp
           Files: 2     Blocks: 4     Bytes: 747



You're welcome. :-)


