标题: 纯DOS下FOR语句执行,字符筛选得变量问题
[打印本页]
作者: jastyg
时间: 2007-2-5 01:02
标题: 纯DOS下FOR语句执行,字符筛选得变量问题
@echo off
ghost -dd
for %%i in (10,9,8,7,6,5,4,3,2,1) do find /i "1.%%i [ibm_service]" | if errorlevel 0 set p=%%i | echo %p%
======================================
以上不能显示出变量P。
不知道错在什么地方。
望指教~~~
[
Last edited by jastyg on 2007-2-7 at 03:44 AM ]
作者: redtek
时间: 2007-2-5 06:13
其中一个错误在这里: if errorlevel 0 set p=%%i | echo %p%
设置变量与显示一个变量不要利用管道的特性而将它们写在同一行中:)
ghost -dd 执行完后是不是要生成一个文件?而 find /i "1.%%i [ibm_service]" 指令要在上面生成的这个文件中检索吧?
ghost -dd 执行后生成的文件就是要被检索的文件,是不是楼主忘了把这个名字给 find 了?
[
Last edited by redtek on 2007-2-4 at 09:03 PM ]
作者: anqing
时间: 2007-2-5 07:24
find /i "1.%%i [ibm_service]"
是在[ibm_service]中,找1.%%i字符串吗?
是这个意思吗?
作者: jastyg
时间: 2007-2-5 11:33
ghost -dd >nul
for %%i in (15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) do find /i "1.%%i: [ibm_service]" ghststat.txt | if errorlevel 1 set p=%%i
我原来这样写的,谢谢2楼朋友指正。
你说的不能在同一行,那怎么解决我这个问题
3楼朋友,你说的没错,就这个意思
作者: NaturalJ0
时间: 2007-2-5 21:33
for %%i in (15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) do call :FIND %%i
GOTO :END
:FIND
find /i "1.%1: [ibm_service]" ghststat.txt
if errorlevel 1 set p=%1
:END
这样也许可以
作者: jastyg
时间: 2007-2-6 04:34
楼上朋友能做个大概的解释么?
%dbg%是什么意思?
FOR里用的是%%i,怎么下面就用%l了?什么意思?
[
Last edited by jastyg on 2007-2-6 at 06:01 AM ]
作者: redtek
时间: 2007-2-6 05:52
不好意思,刚发现我6楼写的代码是错误的(删掉了)。
在原代码中: find /i "1.%1: [IBM_SERVICE]" ghststat.txt 从命令上看,是要在 ghststat.txt 文件中检索含有 1.1(或一直到 1.15): [IBM_SERVICE] 在同一行的字符串。
刚才我分了两个区,在D盘设置卷标为 IBM_SERVICE 来模拟兄所说的那个分区标置好做实验,结果发现在 ghststat.txt 文件中根本就没有在同一行的类似 1.1 .. 或 1.10: [IBM_SERVICE]等这样的标置,……它只有 [IBM_SERVICE] 的节,在节下面有很多项(我不懂一键还原以及命令行下使用参数直接操作 ghost ,所以我不太清楚 1.1 .... 1.15 这些含意。
即,find /i "1.%1: [IBM_SERVICE]" ghststat.txt 命令找不到 类似在同一行中的标置。
Quote: |
*********************************
Date : Mon Feb 5 16:41:27 2007
Error Number: (0)
Message: Stats Dump
Version: 2003.775 (Aug 14 2002, Build=775)
Command line arguments: -dd
Active Switches :
AutoName
ProgMode : no progmode
PathName :
DumpFile :
DumpPos : 0
File64 buffersize : 0
FlagImplode : 0
FlagExplode : 0
Operation Details :
Total size.........0
MB copied..........0
MB remaining.......0
Percent complete...0%
Speed..............0MB/min
Time elapsed.......0:00
Time remaining.....0:00
Program Call Stack
sub_main
main
Call Stack
0x0023b4f7
0x0006b0af
0x00002657
0x00004349
0x0000370b
0x00248bf8
End Call Stack
Start heap available: 26869760
Cur heap available: 26804224
Total Memory: 31326208
Conventional Memory
Inital Conventional Memory Size = 542704
Current Conventional Memory Size = 473648
Allocated
1024 DpmiDjgpp.cpp:59
33504 ghost.cpp:911
528 IdeDmaServerPci.cpp:132
528 IdeDmaServerPci.cpp:132
32 DiskDriveAccessExInt13.cpp:107
Free
16 MsdosFile.cpp:92
80 DiskDriveAccessExInt13.cpp:93
512 DiskDriveAccessInt13.cpp:177
32768 BlockDeviceDosDrive.cpp:290
Fat details:
SRC:
FatType..........16
first_sect.......1229823
ClusterSize......8192
clusters.........53895
root_next_avail..0
data_next_avail..0
dir_sector.......0
root_sector......423
data_sector......455
FAT_sector.......0
NTFS details:
----------------
NTFS Global Flags:
----------------
contiguousWrite=1 forceDiskClusterMapping=0
inhibitCHKDSK=1 ignoreBadLog=0 ignoreCHKDSKBit=0
enable_cache=0 xfrbuflen=0
last_attr_type = 0
----------------
Disk Info :
remote.............0
drive..............0
sectors_used.......2092482
estimated_used.....17574
pemax..............2
Version............0
# Ord Boot Id Ext First Num Last Used NTFS
0 0 80 6 No 00000063 01229697 01229760 00017071 No
1 1 0 6 Yes 01229823 00862785 02092608 00000503 No
Disk Info :
remote.............0
drive..............0
sectors_used.......0
estimated_used.....0
pemax..............0
Version............0
# Ord Boot Id Ext First Num Last Used NTFS
Drive 128 VMware Virtual IDE Hard Drive 00000000000000000001
Int 13h
Total Sectors 2092608
Bytes per Sector 512
MB 1021
Cylinders 519
Heads 64
Sectors per Track 63
Extended Int 13h
Total Sectors 2097152
Bytes per Sector 512
MB 1024
IDE using PIO
Total Sectors 2097152
Bytes per Sector 512
MB 1024
Cylinders 2080
Heads 16
Sectors per Track 63
IDE using UDMA (Active)
Total Sectors 2097152
Bytes per Sector 512
MB 1024
Cylinders 2080
Heads 16
Sectors per Track 63
Remote Drives
AsyncIo : 0
Image Devices
Key A:
Path A:
Desc
Type Floppy
Key C:
Path C:
Desc [SYSTEM_C]
Type Disk
Disk 0
Offset 63
Key D:
Path D:
Desc [IBM_SERVICE]
Type Disk
Disk 0
Offset 1229823
Key @CD-R1
Path @CD-R1
Desc NERO IMAGEDRIVE2
Type DVD
********************************* |
|
除红色标示的 [IBM_SERVICE] 之外我找不到 1.1: 一直到 1.15: 之间变化的内容。或许是我这里生成的这个文件与兄所在磁盘生成的文件有些区别或是其它原因……
是我没看清标题与不懂 Ghsot 到底这些参数都是什么……
希望了解IBM一键还原以及熟悉具体要提及 ghststat.txt 的哪些内容和具体格式的网友能帮兄写上解决代码:)
[
Last edited by redtek on 2007-2-5 at 05:06 PM ]
作者: jastyg
时间: 2007-2-6 11:17
由于GDISK在DELL的机器上运行会死机(GDISK11没试过),所以打算用这个方法对最后的分区进行定位
我不清楚你的怎么会这样,但我在我的机器和别的机器上的GHSTAT结果都跟你不同,你看我的。
*********************************
Date : Mon Feb 5 22:10:45 2007
Error Number: (0)
Message: Stats Dump
Version: 11.0.0.1502 (Dec 4 2006, Build=1502)
OS Version: DOS v7.10
Command line arguments: -dd
Active Switches :
AutoName
PathName :
DumpFile :
DumpPos : 0
FlagImplode : 0
FlagExplode : 0
Operation Details :
Total size.........0
MB copied..........0
MB remaining.......0
Percent complete...0%
Speed..............0 MB/min
Time elapsed.......0:00
Time remaining.....0:00
Program Call Stack
sub_main
main
Call Stack
0x0039623c
0x0009cbd1
0x0000307e
0x00004ce1
0x00003f2f
0x0039f468
End Call Stack
Start heap available: 247726080
Cur heap available: 247529472
Total Memory: 255197184
Allocated
1024 DpmiDjgpp.cpp:56
33504 ghost.cpp:1394
64 DiskDriveAccessExInt13.cpp:139
48 DiskDriveAccessExInt13.cpp:139
528 IdeDmaServerPci.cpp:127
528 IdeDmaServerPci.cpp:127
Free
80 DiskDriveAccessExInt13.cpp:102
2048 DiskDriveAccessInt13.cpp:184
32768 BlockDeviceDosDrive.cpp:392
Fat details:
NTFS details:
----------------
NTFS Global Flags:
----------------
contiguousWrite=1 forceDiskClusterMapping=0
inhibitCHKDSK=1 ignoreBadLog=0 ignoreCHKDSKBit=0
enable_cache=0 xfrbuflen=0
last_attr_type = 0
loadExact = 0
----------------
Disk Info :
remote.............0
drive..............0
sectorsUsedCount.......62910288
estimatedUsedCount.....0
numPartitions..............4
Version............0
# Ord Boot Id Ext First Num Last Used NTFS
0 0 1 7 No 63 15727572 15727635 0 No
1 1 0 b Yes 15727698 26716032 42443730 0 No
2 2 0 b Yes 42443793 16916382 59360175 0 No
3 3 0 1c No 59360238 3550302 62910540 0 No
Disk Info :
remote.............0
drive..............0
sectorsUsedCount.......0
estimatedUsedCount.....0
numPartitions..............0
Version............0
# Ord Boot Id Ext First Num Last Used NTFS
Fixed Drives
Drive 128
Int 13h
Total Sectors 15454530
Bytes per Sector 512
MB 7546
Cylinders 962
Heads 255
Sectors per Track 63
Successful IO Count 0
Extended Int 13h (Active)
Total Sectors 62914560
Bytes per Sector 512
MB 30720
Successful IO Count 138
Floppy Drives
Drive 0 NECVMWar VMware IDE CDR01 1.00
Int 13h
Total Sectors 2880
Bytes per Sector 2048
MB 5
Cylinders 80
Heads 2
Sectors per Track 18
Successful IO Count 0
Extended Int 13h
Total Sectors 2097151
Bytes per Sector 2048
MB 4095
Successful IO Count 0
ASPI (Active)
Total Sectors 27709
Bytes per Sector 2048
MB 54
Successful IO Count 1
Drive 1
Int 13h (Active)
Total Sectors 2880
Bytes per Sector 512
MB 1
Cylinders 80
Heads 2
Sectors per Track 18
Successful IO Count 1
Remote Drives
AsyncIo : 0
Image Devices
Key[1] 1.1:
Key[2] 1:1
Path 1.1:
Desc 1.1: []
Type NTFS
Disk 0
Offset 63
Key[1] 1.2:
Key[2] 1:2
Key[3] C:
Path C:
Desc C: 1.2: []
Type FAT
Disk 0
Offset 15727698
Key[1] 1.3:
Key[2] 1:3
Key[3] D:
Path D:
Desc D: 1.3: []
Type FAT
Disk 0
Offset 42443793
Key[1] 1.4:
Key[2] 1:4
Path 1.4:
Desc 1.4: [IBM_SERVICE]
Type FAT
Disk 0
Offset 59360238
Key[1] A:
Path A:
Desc A:
Type Floppy
Key[1] B:
Path B:
Desc B:
Type Floppy
Key[1] E:
Path E:
Desc E: [NEW]
Type CD
Key[1] X:
Path X:
Desc X: [MS-RAMDRIVE]
Type Disk
Key[1] @CD-R1
Path @CD-R1
Desc @CD-R1 NECVMWarVMware IDE CDR01
Type CD
ConvMemoryAllocationFactoryDpmi diagnostic...
=============================================
Conventional Memory
Initial Conventional Memory Size = 481264
Current Conventional Memory Size = 410608
Allocated
1024 DpmiDjgpp.cpp:56
33504 ghost.cpp:1394
64 DiskDriveAccessExInt13.cpp:139
48 DiskDriveAccessExInt13.cpp:139
528 IdeDmaServerPci.cpp:127
528 IdeDmaServerPci.cpp:127
Free
80 DiskDriveAccessExInt13.cpp:102
2048 DiskDriveAccessInt13.cpp:184
32768 BlockDeviceDosDrive.cpp:392
DiskManager diagnostic...
=========================
Fixed Drives
Drive 128
Int 13h
Total Sectors 15454530
Bytes per Sector 512
MB 7546
Cylinders 962
Heads 255
Sectors per Track 63
Successful IO Count 0
Extended Int 13h (Active)
Total Sectors 62914560
Bytes per Sector 512
MB 30720
Successful IO Count 138
Floppy Drives
Drive 0 NECVMWar VMware IDE CDR01 1.00
Int 13h
Total Sectors 2880
Bytes per Sector 2048
MB 5
Cylinders 80
Heads 2
Sectors per Track 18
Successful IO Count 0
Extended Int 13h
Total Sectors 2097151
Bytes per Sector 2048
MB 4095
Successful IO Count 0
ASPI (Active)
Total Sectors 27709
Bytes per Sector 2048
MB 54
Successful IO Count 1
Drive 1
Int 13h (Active)
Total Sectors 2880
Bytes per Sector 512
MB 1
Cylinders 80
Heads 2
Sectors per Track 18
Successful IO Count 1
The following devices do not use an IRQ:
(0x00, 0x00, 0x00): IRQ: 0x00, INT#: -, Link: 0x00
Class: Bridge, SubClass: Host/PCI
Vendor: 0x8086, Device: 0x7190, RoutePINS: 0x60, 0x61, 0x62, 0x63,
(0x00, 0x01, 0x00): IRQ: 0x00, INT#: -, Link: 0x00
Class: Bridge, SubClass: PCI/PCI
Vendor: 0x8086, Device: 0x7191, RoutePINS: 0x60, 0x61, 0x00, 0x00,
(0x00, 0x07, 0x00): IRQ: 0x00, INT#: -, Link: 0x00
Class: Bridge, SubClass: PCI/ISA
Vendor: 0x8086, Device: 0x7110, RoutePINS: 0x60, 0x61, 0x62, 0x63,
(0x00, 0x07, 0x01): IRQ: 0xff, INT#: -, Link: 0x00
Class: Mass Storage, SubClass: IDE Controller
Vendor: 0x8086, Device: 0x7111, RoutePINS: 0x60, 0x61, 0x62, 0x63,
(0x00, 0x07, 0x03): IRQ: 0x00, INT#: -, Link: 0x00
Class: Bridge, SubClass: Other Bridge
Vendor: 0x8086, Device: 0x7113, RoutePINS: 0x60, 0x61, 0x62, 0x63,
(0x00, 0x0f, 0x00): IRQ: 0xff, INT#: -, Link: 0x00
Class: Display, SubClass: VGA compatible
Vendor: 0x15ad, Device: 0x0405, RoutePINS: 0x60, 0x61, 0x62, 0x63,
The following hard wire-ord devices share IRQ 11:
(0x00, 0x10, 0x00): IRQ: 0x0b, INT#: A, Link: 0x61
Class: Mass Storage, SubClass: SCSI Controller
Vendor: 0x104b, Device: 0x1040, RoutePINS: 0x61, 0x62, 0x63, 0x60,
The following hard wire-ord devices share IRQ 10:
(0x00, 0x11, 0x00): IRQ: 0x0a, INT#: A, Link: 0x62
Class: Network, SubClass: Ethernet
Vendor: 0x1022, Device: 0x2000, RoutePINS: 0x62, 0x63, 0x60, 0x61,
The following hard wire-ord devices share IRQ 9:
(0x00, 0x07, 0x02): IRQ: 0x09, INT#: D, Link: 0x63
Class: Serial Bus, SubClass: USB UHCI
Vendor: 0x8086, Device: 0x7112, RoutePINS: 0x60, 0x61, 0x62, 0x63,
(0x00, 0x12, 0x00): IRQ: 0x09, INT#: A, Link: 0x63
Class: Multimedia, SubClass: Audio
Vendor: 0x1274, Device: 0x1371, RoutePINS: 0x63, 0x60, 0x61, 0x62,
FilesystemManager diagnostic...
===============================
Volume 1
VolumePos: 1.2:
DriveLetter: C:
Description: 12.74GB Logical Disk 0 Offset 7.50GB 12.74GB
Type: fsfFat32
Name:
Volume 2
VolumePos: 1.3:
DriveLetter: D:
Description: 8.07GB Logical Disk 0 Offset 20.24GB 8.07GB
Type: fsfFat32
Name:
Volume 3
VolumePos: 1.1:
DriveLetter:
Description: 7.50GB Primary Disk 0 Offset 31.50KB 7.50GB
Type: fsfNtfsWindowsXP
Name:
Volume 4
VolumePos: 1.4:
DriveLetter:
Description: 1.69GB Primary Disk 0 Offset 28.31GB 1.69GB
Type: fsfFat32
Name: IBM_SERVICE
FilesystemMounter diagnostic...
===============================
LfoFilesystemManager diagnostic...
==================================
Filesystem Index: 0
Filesystem Descriptor:
ID's:
ID Type: 2
ID: A:
DriveType: 2
No FilesystemInfo structure.
Filesystem has no VolumePtr
Filesystem Index: 1
Filesystem Descriptor:
ID's:
ID Type: 2
ID: B:
DriveType: 2
No FilesystemInfo structure.
Filesystem has no VolumePtr
Filesystem Index: 2
Filesystem Descriptor:
ID's:
ID Type: 2
ID: C:
ID Type: 1
ID: 1.2:
DriveType: 4
FilesystemInfo:
formatType: 3
volumeName:
Filesystem Index: 3
Filesystem Descriptor:
ID's:
ID Type: 2
ID: D:
ID Type: 1
ID: 1.3:
ID Type: 4
ID: :
DriveType: 4
FilesystemInfo:
formatType: 3
volumeName:
Filesystem Index: 4
Filesystem Descriptor:
ID's:
ID Type: 2
ID: E:
DriveType: 8
No FilesystemInfo structure.
Filesystem has no VolumePtr
Filesystem Index: 5
Filesystem Descriptor:
ID's:
ID Type: 2
ID: X:
DriveType: 32
No FilesystemInfo structure.
Filesystem has no VolumePtr
Filesystem Index: 6
Filesystem Descriptor:
ID's:
ID Type: 1
ID: 1.1:
DriveType: 4
FilesystemInfo:
formatType: 8
volumeName:
Filesystem Index: 7
Filesystem Descriptor:
ID's:
ID Type: 1
ID: 1.4:
ID Type: 4
ID: IBM_SERVICE:
DriveType: 4
FilesystemInfo:
formatType: 3
volumeName: IBM_SERVICE
*********************************
不管怎么说,先对你说声谢谢!!
作者: redtek
时间: 2007-2-6 11:40
看到了~:)
Desc 1.4: [IBM_SERVICE] 兄生成的文件中有这句,我生成的文件中没有 1.4 或与之类似的数字,我在虚拟机中分了2个区(FAT32),没有NTFS分区,会不会与这相关?
我再用兄的这个生成的文件试一下能否检索出来:)
Quote: |
- @echo %dbg% off
- if NOT [%1]==[] goto :SEARCH
- ghost -dd >nul
- for %%i in (15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) do CALL %0 %%i
- goto :END
- :SEARCH
-
- find /i "1.%1: [IBM_SERVICE]" ghststat.txt >NUL
- if NOT exist ghststat.txt goto :END
- if errorlevel 2 goto :END
- if errorlevel 1 goto :END
- SET p=%1
- Echo 1.%p%: [IBM_SERVICE]
- :END
发表于: 2007-02-05 22:43 |
|
可以了,用兄生成的文件可以成功检索到,兄再试一下看看能不能用:)
===========================================
代码中: 第17行:将从for中依次提取检索的数字与 1.%%i: [IBM_SERVICE]字符串相匹配的数字存放变量P中。
将来要调用这个找到的数字时,就使用变量 %P%
第07行:通过for枚举每一个数字,使用call来模拟递归调用并带入%%i依次枚举出的数字。
当通过call调用时,是在调用自己,所带的参数将被主代码识别为 %1。
第04行:专为递归调用做准备。
如果有代码call自己(第07行call的),那么一定有%1的参数,所以就转到:SEARCH段处理。
如果发现没有参数,那么说明是正常运行,不是被程序调用。
当成功检索到与 [IBM_SERVICE] 相匹配的数字时,会存放变量 %P%中,所以在第18行可以插入自己的代码(如进行 Ghost 备份或恢复……)
[
Last edited by redtek on 2007-2-7 at 10:20 AM ]
作者: jastyg
时间: 2007-2-7 00:38
谢谢,十分感谢.晚上我回去试一下.
不知道兄知道如何用XSET,解决这个问题么?(题外话)
%dbg%是什么意思?多谢兄的代码和详细解释.
作者: redtek
时间: 2007-2-7 00:57
echo %dbg% off
为了方便调试。想看到运行过程或是错误发生在哪里。就得 echo on ,然后脚本存盘再试运行,改完错误后再改回来 echo off 。
有时候这样来回来去的调试要数十次,就得 echo on /off 之间来回来去的改,还要存盘,太麻烦……
于是 echo %dbg% off ,平时 %dbg% 变量是空的,还没赋值,所以一运行的时候系统就默认为 echo off :)
当我在命令行上直接输入: SET DBG=ON 时,就有了这个变量,再运行批处理时,遇到 Echo %dbg% off 就会转变成: echo on off (但只要 echo 后面有一个on 就行了)就可以看到调试信息了。
等不想调试时,就在命令行上键入 SET DBG= 等号后面什么都没有,这样就把这个变量给消了,再运行时就是正常状态:)
XSET 没用过~:)
作者: jastyg
时间: 2007-2-7 03:31
太奇妙了.另外想问一个,上次在人家BAT里看到一个命令,可以阻止CTRL+C中断BAT运行的,当时没留意现在想不起来了~~
兄弟知道啊?
作者: jastyg
时间: 2007-2-7 03:45
刚才在坛子里找个小程序:)
作者: redtek
时间: 2007-2-7 04:01
在 MS-DOS 里,CONFIG.SYS 配置文件中有一个定义:
BREAK=ON 或是 BREAK=OFF
可以 “允许、禁止扩展 Ctrl+BREAK检查” :)
在 Windows CMD 下的窗口里无效:)
不过,也可以用其它方法办到锁定 Windows CMD 窗口内的键盘使用,只是做起来太麻烦(批处理调用Debug写一小段汇编代码来屏蔽键盘中断可以实现)。
作者: jastyg
时间: 2007-2-7 09:40
BREAK=ON
试过好象对CTRL+C没效果
作者: jastyg
时间: 2007-2-7 10:49
把内容复制到re.bat里
输入re.bat,得到15个错误命令的提示,查看发现call re.bat.bat 1---15有循环
输入re就直接call re.bat.bat 15,然后结束,没循环
我把%0.bat改为 %0,结果与上一样,很奇怪!!
[
Last edited by jastyg on 2007-2-7 at 11:30 AM ]
作者: redtek
时间: 2007-2-7 12:57
这问题好象以前遇到过,和 MS-DOS 对 %0 变量的赋值有关,而且特别有意思:)
在执行一个批处理文件时(MS-DOS),在命令提示符的右边和在回车键之前所输入的内容,就是运行一个批处理文件时的 %0 的参数内容:)
如下实验:
@echo off
REM 下面是显示字符串 CALL %0.BAT 来验证批处理%0参数的范围
echo CALL %0.bat
我把 re.bat (上面批处理文件)放入 C:\DEMO\ 目录内。
在目录内执行:
re
会显示结果:
CALL RE.BAT
这 %0 就是刚才键入的 re 。
再试验键入批处理全称:
re.bat
显示结果:CALL re.bat.bat
实际上 re.bat 是我们键入的内容。在re.bat后面的.bat 是在批处理中写的内容:)
然后,我们在 c:\DOS 目录中直接调用 C:\DEMO\RE.BAT 这个批处理文件;
C:\DOS> ..\demo\re.bat
显示结果: CALL ..\demo\re.bat.bat
如果我写不同的大小写来调用:
C:\DOS> ..\demo\Re.bAt
显示结果: CALL ..\demo\Re.bAt.bat
根据上面实验,%0参数是来自DOS命令提示符右边到按回车键之间的所输入的全部内容:)
所以,我原编的代码没想到这点,有问题:)
兄,调用这个批处理的时候先不要加扩展名,或是根据上面实验改动一下:)
作者: jastyg
时间: 2007-2-7 13:04
现在问题解决了
输入的时候不加扩展名,另外把你的只当作对变量的定义,不在里面做任何别的程序完全没问题,如果加了运行GHOST,就不能循环了。
作者: redtek
时间: 2007-2-7 23:21
多谢jastyg兄提示,call %0.bat ... 已改正了: call %0 ... :)
作者: redtek
时间: 2007-2-7 23:34
Quote: |
Originally posted by jastyg at 2007-2-7 00:04:
现在问题解决了
输入的时候不加扩展名,另外把你的只当作对变量的定义,不在里面做任何别的程序完全没问题,如果加了运行GHOST,就不能循环了。 |
|
我不懂Ghost命令行加参数操作(这部份我实验起来可能会遇到很多麻烦或错误百出:)
兄通晓Ghost命令行参数等操作,建议兄只当9楼代码功能为: 如果发现了 1.?: [IBM_SERVICE] 就自动将其?问号处数字值赋与变量 %P% ,然后退出批处理。
这样在环境变量中就有了变量%P%,然后兄再使用Ghost加变量%P%做其中的参数之一来进行恢复或是备份操作:)
(假如下面是总调用代码:)
CALL 第9楼代码
GHOST 后面参数中含有%P%
作者: jastyg
时间: 2007-2-8 02:07
对,现在就跟你上面说的想法一致,就是这样做的.
从你的BAT里获得%P%
然后退出你的BAT
运行ghost -clone,mode=pload,src=ibm.gho:1,dst=1:%p% -sure -fx
运行没任何问题.
这样做的确实就是查找的时间稍微长了点,而且准确性只能达到无限接近.
如果可以通过比如:
[IBM_SERVICE]和前面的DESC这2个字符的位置,通过筛选得到%P%,这样就更准确,而且时间方面也应该会减少!
以前Wengier帮我写过一个的是通过XSET筛选并定义%p%.
兄有兴趣我可以发给你看看!
[
Last edited by jastyg on 2007-2-8 at 02:31 AM ]
作者: redtek
时间: 2007-2-8 02:22
多谢兄指点和提供了更好的实现方法~:)
我一会儿去看一下XSET和相关Ghost的东东~:)
作者: jastyg
时间: 2007-2-8 02:34
http://blog.cersp.com/userlog3/71202/archives/2007/243983.shtml
里有一些关于XSET的用法
作者: redtek
时间: 2007-2-8 05:19
改进了一下,不再使用FOR循环CALL自己,因每CALL自己一次直至代码找到目标及全部代码运行完共约执行15次(或以上)CALL和FIND操作…
一次将15个参数直接CALL出去,然后一次性通过SHIFT命令左移每一位被CALL的参数来处理,这样总共代码以及被CALL的程序调用,一共只用约3次完成,即从原来的15次以上的处理过程减少至只到目标出现为止。
先FIND生成只有一行的含有 [IBM_SERVICE] 目标串的行,然后在以后的FIND调用过程只要对只有这一行的目标文件操作,速度提高了一部分。
根据多次实验,只有ghost -dd >nul 这句是 Ghost 生成磁盘等信息文件的参数,这个最浪费时间,希望Ghost开发公司对生成此文件的速度有待改进。如果不是Ghost -dd 浪费时间,下面代码执行总时间约在1秒以内。
@echo %dbg% off
if NOT [%1]==[] goto :SEARCH
ghost -dd >nul
find "[IBM_SERVICE]" ghststat.txt > tmp.tmp
call %0 -,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
goto :END
:SEARCH
shift
if [%1]==[] goto :end
find "1.%1: [IBM_SERVICE]" ghststat.txt > tmp.tmp
if errorlevel 1 goto :SEARCH
SET p=%1
:: ============================ info list =======
Echo 1.%p%: [IBM_SERVICE]
Echo P=%p%
:: ==============================================
del tmp.tmp >nul
:END
多谢qzwqzw兄指点,代码已更正~:)
[
Last edited by redtek on 2007-2-7 at 04:38 PM ]
作者: qzwqzw
时间: 2007-2-8 05:33
:Search段有问题
shift不应插在if与find的中间
if errorlevel 2 是没有必要的
作者: redtek
时间: 2007-2-8 05:36
多谢qzwqzw兄指点~:)))
作者: jastyg
时间: 2007-2-8 23:00
多谢兄弟们的帮忙
对了,关于 shift的用法能说明一下么?我搜索了本站相关内容说的有些含糊(或者我理解能力差),还是搞不清!
谢谢
作者: redtek
时间: 2007-2-9 02:43
Shift 命令在很多教程里写得太复杂(主要是作者在写Shift命令的时候把一些不相关的内容全都加了进去故意造就一种强大而复杂玄虚的释解,让人看到最后都不知道作者在说什么:)
有一个帖子里关于 Shift 命令写得特别直接而精彩~:)
shift这个批处理命令的用法 (在下面帖子的第3楼)
http://www.cn-dos.net/forum/view ... amp;highlight=SHIFT
上面帖子大约原理就是每执行一遍 SHIFT ,被 Call 进来(传递进来的参数)就会被全部向左移一位。
这样每执行一次 SHIFT 就向左移一位,如果是在处理 %1 这个参数,就可以象永远在处理 %1 这个参数(但它每次都是动态的,因为SHIFT命令又会把右边的%N参数向左移过来),就是有再多 CALL 过来的参数(如:从%1--%N),全都可以依次的使用Shift将它们一一处理完,直至 %1 为空(未赋值状态)为止:)
作者: jastyg
时间: 2007-2-9 10:20
多实在啊,这下明白了。