Name: dbT83986 Date: 03/03/99
// Compile and run the Java class below. The JVM will hang. It works fine under JDK 1.1.7
// Source code (please note this is an example -with minor modifications to adapt it to Windows- taken from the book "Java
// Class Libraries Second Edition, Volume 1; page 1365):
import java.io.*;
public class ls
{
public static void main(String[] args)
{
try
{
String cmd = "ls.bat";
Process child = Runtime.getRuntime().exec(cmd);
InputStream in = child.getInputStream();
int c, newline = 0, maxlines = 10;
if (args.length > 0)
maxlines = Integer.parseInt(args[0]);
while ((c = in.read()) != -1 && newline < maxlines)
{
char ch = (char)c;
System.out.print(ch);
if (ch == '\n')
++newline;
}
in.close();
child.destroy();
}
catch (IOException ioe)
{
System.err.println(ioe);
}
}
}
(Review ID: 52231)
======================================================================