简体   繁体   中英

How to pass parameters to Windows XP batch file from a text file?

I want to find where is a certain java class from from hundreds jar files. I want to use batch file to do it:

First i get a list of all jar files:

dir /s *.jar > jarfiles.txt

Then create a bacth file findclass.bat:

jar tf %1

finally i run this batch like this:

findclass < jarfiles.txt

But this does not work.

What's wrong and what should I do?

Or any other better way to locate a class than using batch?

see HELP FOR

and then try

FOR /F "delims=" %%A IN (jarfiles.txt) DO findclass %%A

or just

FOR /R %%A IN (*.jar) DO findclass %%A

I think this should work, just replace <your class name> with your class name

@echo off
set JARTEXTFILE=jarfiles.txt

dir /S /B *.txt > %JARTEXTFILE%

for /f "tokens=1,* delims=¶" %%A in ( '"type %JARTEXTFILE%"') do (
    jar tf %%A | findstr /C:"<your class name>"
)

Use my ClassFinder utility. It's simple, fast and built for the purpose!

http://www.adarshr.com/papers/classfinder

Usage:

   java  -jar  cf.jar  SEARCH  [DIRECTORY]  [OPTIONS]...

Searches all JAR files in the current directory and its sub-directories for
entries matching the SEARCH argument. If DIRECTORY is provided, searching will
be done in that location instead of the current directory.

SEARCH:

  A search string containing the class name (entry name). Wild card (*) is
  supported. Package separator can be either of `/', `\' or `.'.

  Examples:

    java.lang.String
    java/util/ArrayList
    java/lang/Str*B*er

  If non ".class" entries also need to be searched, option -a (--all-types)
  should be specified. Please see the OPTIONS section for a more detailed
  explanation.

DIRECTORY:

  If this is not provided, current directory and all its sub-directories will
  be used for performing the search. However, if this argument is provided,
  the same and its sub-directories will be used as the location to fetch JAR
  files from.

  If a recursive scan is not needed, option -s (--shallow) can be specified.

OPTIONS:

  -h          --help
                   Shows this help
  -o [path]   --redirect-output
                   Redirect output to a file path supplied.
  -x [x1,x2]  --archive-extensions
                   Extensions in addition to the default ".jar". Comma or space
                   separated list accepted.
  -i          --insensitive-case
                   Case insensitive search.
  -q          --quiet
                   Silent search without the progress bar animation.
  -a          --all-types
                   Removes the filtering on ".class" types so that other types
                   such as ".properties", ".xml", etc can also be searched for.
  -s          --shallow
                   Performs a shallow search. Doesn't recurse.

Examples:

   java  -jar  cf.jar  org/apache/log4j/Level  D:\Frameworks
   java  -jar  cf.jar  *OracleDriver  C:\oracle -x jar,zip
   java  -jar  cf.jar  messages.properties  D:\IBM\WebSphere -a -x jar,war,ear
   java  -jar  cf.jar  util.*  D:\Java -i -q

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM