Name: rlT66838 Date: 09/16/99
When using Runtime.exec to execute a windows console program
(findstr.exe), passed a search parameter containing two adjacent
spaces that are either removed or shortened to one space.
The command-line I'm trying to emit is:
findstr /B /C:"AA. " acro.txt
The data file (acro.txt, 46 lines) is as follows:
AA Avenue of Approach
AA Alcoholics Anonymous
AA Automobile Association (in England)
AAA American Automobile Association
AAAL American Academy of Arts and Letters
AAAS American Association for the Advancement of Science
AAII American Association of Individual Investors
AAMSI American Association for Medical Systems Informatics
AAP Affirmative Action Program
AARC Anglo-American Cataloging Rules
ACAA Agricultural Conservation and Adjustment Administration
AIAA American Institute of Aeronautics and Astronautics
AMRAAM Advanced Medium Range Air-To-Air Missile
FAA Federal Aviation Agency
GAAP Generally Accepted Accounting Principles
HP Higher Power (sort of an AA "in" term, usually God)
MAAP Maintenance And Administration Panel
NAACP National Association for the Advancement of Colored People
NAAS North American Automated Systems co.
NOAA National Oceanic and Atmospheric Administration
RAAF Royal Australian Air Force
SAA South Atlantic Anomaly
SAA Systems Application Architecture
AA Associate in Accounting
AA Antiaircraft Artillery
AA Affirmative Action committee
AA Another Acronym
AAA Autonomous Administrative Area
AAI Automated AUTODIN Interface
AAI AUTODIN/AUTOVON Interface
AAI Administration Authority Identifier
AAL ATM Application Layer
AARE Application Associate REsponse
AARNet Australian Academic Research Network
AARP AppleTalk Address Resolution Protocol
AARQ Application Associate ReQuest
AARTS Automatic Audio Remote Test Set
DAAC Distributed Active Archive Center
GAAP Generally Accepted Accounting Principles
ISSAA Information System Selection Acquisition Agency
MAA MAjor synchronize Acknowledge
SAA Systems Application Architecture
THAAD Theater High Altitude Area Defense system
YAA Yet Another Acronym
TANSTAAFL There Ain't No Such Thing As A Free Lunch
THAAD Theater High Altitude Area Defense system
Here is the java code to show the problem:
import java.io.*;
public class jdcbug {
public static void main(String argv[]) {
Runtime rt = Runtime.getRuntime();
Process p;
BufferedReader br;
// Note: 'findstr.exe' is a Microsoft executable found in /windows
// on NT4.0 systems. See findstr /? for more info on parameters.
// The use of a '.' in the search string specifies 'match one and
// only one character'.
String[] command = new String[4];
command[0] = "findstr"; // the lookup program to execute
command[1] = "/B"; // parameter - look at the start of the line.
command[2] = "/C:\"AA. \""; // parameter - the literal search string.
command[3] = "acro.txt"; // parameter - which file to look in.
// Output 1 - array version
try {
p = rt.exec(command);
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String resultLine = "";
while((resultLine = br.readLine()) != null) {
System.out.println(resultLine);
}//end while
} catch(IOException ioe) {
}//end try/catch
System.out.println("\n\n"); // output separator
// Output 2 - string version
String s = "findstr /B /C:\"AA. \" acro.txt";
try {
p = rt.exec(s);
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String resultLine = "";
while((resultLine = br.readLine()) != null) {
System.out.println(resultLine);
}//end while
} catch(IOException ioe) {
}//end try/catch
}//end main
}//end jdcbug
The string[] version of exec produces the following output:
acro.txt:AA Avenue of Approach
acro.txt:AA Alcoholics Anonymous
acro.txt:AA Automobile Association (in England)
acro.txt:AAA American Automobile Association
acro.txt:AAAL American Academy of Arts and Letters
acro.txt:AAAS American Association for the Advancement of Science
acro.txt:AAII American Association of Individual Investors
acro.txt:AAMSI American Association for Medical Systems Informatics
acro.txt:AAP Affirmative Action Program
acro.txt:AARC Anglo-American Cataloging Rules
acro.txt:AA Associate in Accounting
acro.txt:AA Antiaircraft Artillery
acro.txt:AA Affirmative Action committee
acro.txt:AA Another Acronym
acro.txt:AAA Autonomous Administrative Area
acro.txt:AAI Automated AUTODIN Interface
acro.txt:AAI AUTODIN/AUTOVON Interface
acro.txt:AAI Administration Authority Identifier
acro.txt:AAL ATM Application Layer
acro.txt:AARE Application Associate REsponse
acro.txt:AARNet Australian Academic Research Network
acro.txt:AARP AppleTalk Address Resolution Protocol
acro.txt:AARQ Application Associate ReQuest
acro.txt:AARTS Automatic Audio Remote Test Set
while the string version containing the identical command, produces:
AA Avenue of Approach
AA Alcoholics Anonymous
AA Automobile Association (in England)
AAA American Automobile Association
AAP Affirmative Action Program
AA Associate in Accounting
AA Antiaircraft Artillery
AA Affirmative Action committee
AA Another Acronym
AAA Autonomous Administrative Area
AAI Automated AUTODIN Interface
AAI AUTODIN/AUTOVON Interface
AAI Administration Authority Identifier
AAL ATM Application Layer
from the command line,
findstr /B /C:"AA. " acro.txt produces:
AAA American Automobile Association
AAP Affirmative Action Program
AAA Autonomous Administrative Area
AAI Automated AUTODIN Interface
AAI AUTODIN/AUTOVON Interface
AAI Administration Authority Identifier
AAL ATM Application Layer
which is the desired result. If one space is removed from the
above search specifier, it produces the same output as the
string version of exec.
(Review ID: 93835)
======================================================================