生成帮助文件 [英] Generate help files

查看:114
本文介绍了生成帮助文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows cmd中的 help 中为所有命令生成帮助生成器,并将其写入单独的文件。所以你问/?对于在cmd中键入 help 时列表上的所有命令。
这是我的代码的主要部分:

  rem mypath  - 这是一个文件夹, $ b rem In help all命令由大写字母
以/ ftokens = 1 usebackq%% i在(`help ^ | findstr / B / R[QWERTYUIOPASDFGHJKLZXCVBNM] [QWERTYUIOPASDFGHJKLZXCVBNM]`)中(
if NOT%% i==GRAFTABL(
如果没有%% i==DISKPART(
如果没有%% i== (
help %% i>!mypath!\ %% i.txt




我使用[Q..M]中的所有序列在我的Regular exp中,因为只有一组[AZ] $ b但是问题是在我的FOR和IF文件 - 有REM命令的帮助。有谁有任何想法为什么是这样?
要修复它,我使用:

  FOR /? >%mypath%\FOR.txt 
IF /? >%mypath%\IF.txt

但我不明白为什么会这样。

解决方案

您在问题中发布的代码为我提供了正确的结果(甚至在我重新格式化之前) p>

请参阅为什么findstr无法正确处理(在某些情况下)?解释为什么[AZ]不能正常工作与FINDSTR。有关已知FINDSTR怪癖的详尽列表,请参见 Windows FINDSTR命令的未记录的功能和限制



过滤掉命令名称的更好方法是查找以至少一个非空格字符开头的行,后跟任意数量的其他非空格字符,后跟2空格。



如果你想忽略某些命令,你可以简单地使用一个额外的FINDSTR和/ V选项。



解决方案成为一个可以从命令提示符运行而不使用批处理脚本的合理的一个线程:

  A in('help ^ | findstr / rc:^ [^] [^] *^ | findstr / vGRAFTABL DISKPART SC')do @help%A>%A.txt 

或作为可插入脚本的代码:

  for / f %% A in(
'help ^ | findstr / rc:^ [^] [^] *^ | findstr / vGRAFTABL DISKPART SC'
)帮助%% A>!mypath!\ %% A.txt


EDIT - 2015-10-11



HELP输出的第一行和最后一行以我的英语机器上的(混合大小写)开始。这个词恰好是一个有帮助的有效命令,所以FOR.TXT文件创建了3次。



我假设所有语言使用混合大小写的第一个和最后一个线。不难修改FINDSTR过滤器以排除第二个字符是空格或小写字符的任何行:

  for / f%A in('help ^ | findstr /rvc:\"^.[abcdefghijklmnopqrstuvwxyz]^ | findstr / vGRAFTABL DISKPART SC')do @help%A>%A.txt 


I wanted to make help generator for all command in help in Windows cmd and write it to separate files. So you are asking /? on all commands that are on the list when you type help in cmd. Here are the main part of my code:

rem mypath - it's a folder where I put my results
rem In help all command are written by capitals letters
for /f "tokens=1 usebackq" %%i in (`help^|findstr /B /R "[QWERTYUIOPASDFGHJKLZXCVBNM][QWERTYUIOPASDFGHJKLZXCVBNM]"`) do (
  if NOT "%%i"=="GRAFTABL" (
    if NOT "%%i"=="DISKPART" (
      if NOT "%%i"=="SC" (
        help %%i > !mypath!\%%i.txt
      )
    )
  )
)

I use all sequence from [Q..M] in my Regular exp because there are some problems with just set of [A-Z] But the problem is that in my FOR and IF files - there are help for REM command. Does anyone have any idea why is it so ? To fix it I use:

FOR/? >%mypath%\FOR.txt
IF/? >%mypath%\IF.txt

But I can't understand why it is so.

解决方案

The code you posted in your question gives the correct result for me (even before I reformatted it a bit).

See Why does findstr not handle case properly (in some circumstances)? for an explanation of why [A-Z] does not work properly with FINDSTR. For an exhaustive list of known FINDSTR quirks, see What are the undocumented features and limitations of the Windows FINDSTR command?

A better way to filter out command names is to look for lines that begin with at least one non-space character, followed by any number of additional non-space characters, followed by 2 spaces.

If you want to ignore certain commands, you can simply use an additional FINDSTR with the /V option.

The solution becomes a reasonable one liner that can run from the command prompt without a batch script:

for /f %A in ('help^|findstr /rc:"^[^ ][^ ]*  "^|findstr /v "GRAFTABL DISKPART SC"') do @help %A >%A.txt

Or as code that can be plugged into your script:

for /f %%A in (
  'help^|findstr /rc:"^[^ ][^ ]*  "^|findstr /v "GRAFTABL DISKPART SC"'
) do help %%A >"!mypath!\%%A.txt"


EDIT - 2015-10-11

The first and last lines of HELP output start with the word For (mixed case), on my English machine. That word happens to be a valid command with help, so the FOR.TXT file gets created 3 times.

I presume that all languages use mixed case for the first and last line. It is not hard to refine the FINDSTR filter to exclude any line where the 2nd character is space or a lower case character:

for /f %A in ('help^|findstr /rvc:"^.[abcdefghijklmnopqrstuvwxyz ]"^|findstr /v "GRAFTABL DISKPART SC"') do @help %A >%A.txt

这篇关于生成帮助文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆