无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
楼主: lianjiang
打印 上一主题 下一主题

grub4dos传递参数的方法

[复制链接]
1#
发表于 2009-3-6 21:51:32 | 显示全部楼层
现在极度郁闷
做个几个菜单给DOS传递参数,用的就是这几种方法。
  1. @echo off
  2. find  "11" a:\defaut.txt  > nul
  3. if not errorlevel 1  a:\PM.bat
  4. find  "22" a:\defaut.txt  > nul
  5. if not errorlevel 1  a:\DM.bat
  6. find  "33" a:\defaut.txt  > nul
  7. if not errorlevel 1  a:\GHOST.bat
复制代码
a:\defaut.txt  应该是 a:\default.txt

另外 find  "11" a:\defaut.txt > nul  不可靠,不是所有数字都能使用!
我还没想到在纯DOS下可靠的判断方法。
那位高手帮助改进一下.

[ 本帖最后由 happymy 于 2009-3-7 00:49 编辑 ]
回复

使用道具 举报

2#
发表于 2009-3-7 10:40:49 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 07:52 发表


不明白什么叫“另外 find  "11" a:\defaut.txt > nul  不可靠,不是所有数字都能使用!”

最好用实例说明哪里有问题,你是如何使用的。


确实有问题。例如
  1. find "10" a:\default.txt > nul
  2. if not errorlevel 1 echo  10
  3. find "12" a:\default.txt > nul
  4. if not errorlevel 1 echo 12
  5. find "13" a:\default.txt > nul
  6. if not errorlevel 1 echo 13
  7. find "14" a:\default.txt > nul
  8. if not errorlevel 1 echo 14
  9. find "16" a:\default.txt > nul
  10. if not errorlevel 1 echo 16
  11. find "17" a:\default.txt > nul
  12. if not errorlevel 1 echo 17
  13. find "18" a:\default.txt > nul
  14. if not errorlevel 1 echo 18
  15. find "20" a:\default.txt > nul
  16. if not errorlevel 1 echo 20
  17. find "21" a:\default.txt > nul
  18. if not errorlevel 1 echo 21
  19. find "22" a:\default.txt > nul
  20. if not errorlevel 1 echo 22
  21. find "24" a:\default.txt > nul
  22. if not errorlevel 1 echo 24
  23. find "25" a:\default.txt > nul
  24. if not errorlevel 1 echo 25
  25. find "26" a:\default.txt > nul
  26. if not errorlevel 1 echo 26
  27. find "28" a:\default.txt > nul
  28. if not errorlevel 1 echo 28
  29. find "29" a:\default.txt > nul
  30. if not errorlevel 1 echo 29
  31. find "30" a:\default.txt > nul
  32. if not errorlevel 1 echo 30
  33. find "32" a:\default.txt > nul
  34. if not errorlevel 1 echo 32
  35. find "33" a:\default.txt > nul
  36. if not errorlevel 1 echo 33
  37. find "34" a:\default.txt > nul
  38. if not errorlevel 1 echo 34
  39. find "36" a:\default.txt > nul
  40. if not errorlevel 1 echo 36
  41. find "37" a:\default.txt > nul
  42. if not errorlevel 1 echo 37
  43. find "38" a:\default.txt > nul
  44. if not errorlevel 1 echo 38
  45. find "40" a:\default.txt > nul
  46. if not errorlevel 1 echo 40
  47. find "41" a:\default.txt > nul
  48. if not errorlevel 1 echo 41
  49. find "42" a:\default.txt > nul
  50. if errorlevel 1 echo 42
  51. find "44" a:\default.txt > nul
  52. if not errorlevel 1 echo 44
  53. find "45" a:\default.txt > nul
  54. if not errorlevel 1 echo 45
  55. find "46" a:\default.txt > nul
  56. if not errorlevel 1 echo 46
  57. find "48" a:\default.txt > nul
  58. if not errorlevel 1 echo 48
  59. find "49" a:\default.txt > nul
  60. if not errorlevel 1 echo 49
  61. find "50" a:\default.txt > nul
  62. if not errorlevel 1 echo 50
复制代码
折腾了一晚上(我是菜鸟,纯DOS又限制太多……)。我想到了一种更好的方法:

不过有两个缺点:
1.需要建立一个临时文件
2.执行的bat文件名必需和查找的数字相同。

先建立11.bat、12.bat、13.bat、14.bat
  1. @echo off
  2. del temp.bat
  3. cls
  4. type default.txt|find "11" >>temp.bat
  5. type default.txt|find "12" >>temp.bat
  6. type default.txt|find "13" >>temp.bat
  7. type default.txt|find "14" >>temp.bat
  8. temp.bat
复制代码
不要使用0开头的数字。

[ 本帖最后由 happymy 于 2009-3-7 12:38 编辑 ]
回复

使用道具 举报

3#
发表于 2009-3-7 11:05:38 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 11:00 发表


使用的数字不能以0开头,这是grub所要求的,不能称之为问题。

只写出例子,但并未交代哪里有问题。
另外,原始的default.txt存在2024的字符,因此是用原始文件的话,不能用像2,4,20,24,202之类的来 ...


就是所有数字都不能用的问题。 这两种方法各有各的优点。
不生成 temp.bat 就需要第三方工具。
type default.txt|find "14"|call 这种写法我也想过,但是使用call 会返回调用的BAT。
回复

使用道具 举报

4#
发表于 2009-3-7 11:18:57 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 11:11 发表


所有者数字都不能用,这是不可能的。除非你没有按要求做。

笔误(一晚上没睡,有点精神恍惚了),应该是有的数字不能使用。
回复

使用道具 举报

5#
发表于 2009-3-7 11:33:26 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 11:29 发表


请写出哪些数字不能用。

所谓不能用,表现是什么?是写不到default.txt里?

问题交待很不清楚,作为一个版主,实不应该,呵呵。


你刚才不是已经写出来了么?

原始的default.txt存在2024的字符,因此是用原始文件的话,不能用像2,4,20,24,202之类的来判断,需要避开。【例子中的20是不能用的。】

我这种也存在一些问题,用原始的default.txt 发现会输出一些非数字的内容。看来需要继续改进。
回复

使用道具 举报

6#
发表于 2009-3-7 12:36:17 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 11:47 发表



这是问题吗? 假如认为是问题的话,也只能说明没有理解此方法,呵呵。

举出的那几个数字,并非不能用,而是dos下假如采用find "20"之类来处理的话,要避开。
对策:
1,替换掉原始的2024的数字
2, ...


都先说我是DOS菜鸟。

因为find本身的问题,default.txt里面内容又不是空的。
find 在查找字符的时候并不是精确查找,default.txt里的内容会被显示出来。

例如 20


  1. A:\find "20" A:\default.txt
  2. 返回的结果:

  3. ---------- A:\DEFAULT.TXT
  4. 20
  5. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
  6. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
复制代码
另外bat里连续查找某些数字的时候。
返回:
  1. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
  2. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
  3. 查找的数字
  4. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
  5. # !!!!!!! The file size is 2048 bytes. Don't change the file size !!!!!!!
复制代码
我这种方法,在遇到这两种返回结果的时候不会出现问题。查20这个数字也不会出现错误

10-99都不会出现错误。

不足的是看到几行 Bad command or file name

[ 本帖最后由 happymy 于 2009-3-7 12:40 编辑 ]
回复

使用道具 举报

7#
发表于 2009-3-7 12:49:57 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 12:44 发表
当使用菜单很多时,用type判断效率低,可用直接读取第一个数字的办法。

比如nset。

type default.txt|find "14"

type default.txt
是为了去掉 find 返回的
---------- A:\DEFAULT.TXT

另外A:\DEFAULT.TXT 存在于内存中,速度是很快的。

用第三方工具是个不错的方法。
回复

使用道具 举报

8#
发表于 2009-3-7 13:13:12 | 显示全部楼层
原帖由 lianjiang 于 2009-3-7 13:06 发表

因为你的例子,从10一直type到50,用了80行,而直接读取2行就够了。


帮我写个改进的:)

另外1楼的内容修改、添加点内容。

来个完美的,方便大家。
回复

使用道具 举报

9#
发表于 2009-4-9 13:20:24 | 显示全部楼层
简单的测试了一下
savedefault的成功率比DD和write 成功率要高

版本:
grub4dos-0.4.4-2009-02-22

新的没有测试

[ 本帖最后由 happymy 于 2009-4-9 13:25 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-5-19 03:34

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表