Running an External Program From NetRexx

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Running an External Program From NetRexx

BERNIEGS
Hi,

I'm hoping that someone might be able to help with this problem. The
following code is intended to execute an external program, in this
case just a simple directory listing, and then echo its output to the
screen. It works fine until the end of the output stream is reached,
when it just hangs at line 11, and I have to Ctrl-C to end the
program. This program is a simplified version of the NONJAVA.NRX
program in the NetRexx Redbook. The Redbook's version hangs up in just
the same way if I run it right out the book. I must be doing something
wrong, because I have tried numerous published examples of this type
of program, both NetRexx and Java, with identical results. Anyone know
how to get it to terminate normally at the end of the DOS command? I
seem to recall that this kind of program used to work OK under JDK
1.02 and NetRexx 1.0.

My environment is:
  Windows 95
  JDK 1.1.4
  NetRexx 1.121

Any advice will be appreciated. TIA.

-- Bernie --


 1 /* Execute a DOS command */
 2 OPTIONS TRACE1
 3 trace all
 4
 5 line = Rexx ''
 6
 7 child = RunTime.getRunTime().exec('command.com /c dir exec.nrx')
 8 in = BufferedReader(InputStreamReader(child.getInputStream()))
 9
10 loop while line \= null
11   line = in.readline()
12   say line
13 end

Here's what a trace of the program shows:

  5 *=* line = Rexx ''
  7 *=* child = RunTime.getRunTime().exec('command.com /c dir exec.nrx')
  8 *=* in = BufferedReader(InputStreamReader(child.getInputStream()))
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line

 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
 Volume in drive C has no label
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
 Volume Serial Number is 3441-1201
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
 Directory of C:\java\programs
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line

 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
EXEC     NRX           274  11-26-97 11:08a exec.nrx
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
         1 file(s)            274 bytes
 10 *=* loop while line \= null
 11 *=*   line = in.readline()
 12 *=*   say line
         0 dir(s)     259,588,096 bytes free
 10 *=* loop while line \= null
 11 *=*   line = in.readline()

--
Bernie Schneider: [hidden email]
========================================================================
The individual has always had to struggle to keep from being overwhelmed
by the tribe. To be your own man is a hard business. If you try it, you
will be lonely often, and sometimes frightened. But no price is too high
to pay for the priviledge of owning yourself.      << Rudyard Kipling >>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>

Reply | Threaded
Open this post in threaded view
|

Re: Running an External Program From NetRexx

William H. Geiger III-2
-----BEGIN PGP SIGNED MESSAGE-----

In <[hidden email]>, on 11/27/97
   at 07:55 PM, BERNIEGS <[hidden email]> said:

>Hi,

>I'm hoping that someone might be able to help with this problem. The
>following code is intended to execute an external program, in this case
>just a simple directory listing, and then echo its output to the screen.
>It works fine until the end of the output stream is reached, when it just
>hangs at line 11, and I have to Ctrl-C to end the program. This program
>is a simplified version of the NONJAVA.NRX program in the NetRexx
>Redbook. The Redbook's version hangs up in just the same way if I run it
>right out the book. I must be doing something wrong, because I have tried
>numerous published examples of this type of program, both NetRexx and
>Java, with identical results. Anyone know how to get it to terminate
>normally at the end of the DOS command? I seem to recall that this kind
>of program used to work OK under JDK 1.02 and NetRexx 1.0.


> 1 /* Execute a DOS command */
> 2 OPTIONS TRACE1
> 3 trace all
> 4
> 5 line = Rexx ''
> 6
> 7 child = RunTime.getRunTime().exec('command.com /c dir exec.nrx')
> 8 in = BufferedReader(InputStreamReader(child.getInputStream()))
> 9
>10 loop while line \= null
>11   line = in.readline()
>12   say line
>13 end

This reminds me of the behavior of Rexx when pulling data off of a queue.
If the queue is empty it will sit and wait forever for more data to
showup.

What you need to do is peek at the queue before issuing your readline()
command to see if any data is present. This will work in a single threaded
enviroment where all the data is in the queue before you start pulling.

In a multi-threaded enviroment the best thing to do is to push an "end of
data" line onto your queue and then do a check for this in your loop
having it break out once it is received. Otherwise you will run into
timing problems of the queue being empty but not all the data has been
retreived.

You might also want to think about adding a timer and having the routine
error out once it exceeds a predetermined time limit. This would be a
failsafe for any problems that may occure with the external program.


- --
- ---------------------------------------------------------------
William H. Geiger III  http://users.invweb.net/~whgiii
Geiger Consulting    Cooking With Warp 4.0

Author of E-Secure - PGP Front End for MR/2 Ice
PGP & MR/2 the only way for secure e-mail.
OS/2 PGP 2.6.3a at: http://users.invweb.net/~whgiii/pgpmr2.html                       
- ---------------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3a-sha1
Charset: cp850
Comment: Registered_User_E-Secure_v1.1b1_ES000000

iQCVAwUBNIaVkI9Co1n+aLhhAQLGIwP/RNQOsMEDiwwKK4Wxl54SU2MebwvPP3Di
TqW8WVuEGeGcUoUrcYK9wc4cKlj5U/1dvlDbydTnyZHE0idS1mNch/wGFM3J8r/o
QyDtZTYRWvrLJ9eKHtrokL7ZXjUgFBi/ChZLnfyofTD7bJoIt//ltV2aUkqGqb/U
RxHFDxGpDM8=
=lFeD
-----END PGP SIGNATURE-----

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>