如何从文本文件中将参数传递给Windows XP批处理文件?

时间:2011-03-10 14:28:39

标签: redirect parameters input batch-file dos

我想从数百个jar文件中找到某个java类的位置。我想使用批处理文件来执行此操作:

首先我得到所有jar文件的列表:

dir /s *.jar > jarfiles.txt

然后创建一个bacth文件findclass.bat:

jar tf %1

最后我像这样运行这批:

findclass < jarfiles.txt

但这不起作用。

出了什么问题,我该怎么办?

或者找到一个比使用批处理更好的方法?

3 个答案:

答案 0 :(得分:3)

请参阅HELP FOR

然后尝试

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

或只是

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

答案 1 :(得分:2)

我认为这应该有效,只需将<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>"
)

答案 2 :(得分:2)

使用我的ClassFinder实用程序。它简单,快速,专为此目的而设计!

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