![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-23 14:09 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » Problems in making batch processing for ghost continuous backup of three partitions |
| Printable Version 1,887 / 10 |
| Floor1 chjlcn | Posted 2005-08-05 08:16 |
| 初级用户 Posts 7 Credits 43 From 广东 | |
|
cls
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2% md %todayFolder% cd %todayFolder% md c md d md e cd .. ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\d\c.gho -fx -z2 -sure ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure Under Windows, changing ghost to ghost32 can execute, But when executing under Dos, the created directories c, d, e are in g:\ghost\ instead of g:\ghost\%todayFolder\. Finally, c.gho, d.gho, e.gho are under g:\ghost\ instead of the g:\ghos\%todayFolder%\c\, g:\ghost\%todayFolder%\d\, g:\ghost\%todayFolder%\e\ that I wanted. I found that the path prompt when ghost is g:\ghost\\d\c.gho. Is the %todayFolder% parameter invalid? How can it be done? |
|
| Floor2 Climbing | Posted 2005-08-05 09:05 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Try like this:
cls set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2% md g:\ghost\%todayFolder%\c md g:\ghost\%todayFolder%\d md g:\ghost\%todayFolder%\e ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\c\c.gho -fx -z2 -sure ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure |
|
| Floor3 chjlcn | Posted 2005-08-05 15:47 |
| 初级用户 Posts 7 Credits 43 From 广东 | |
|
Thanks for your attention.
But the %todayFolder% parameter is still an empty string under DOS. The created directory is in g:\ghost\\c. It doesn't work... So annoying. |
|
| Floor4 Climbing | Posted 2005-08-05 16:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
In a pure DOS environment, such a way of setting variables is not supported at all:
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2% This setting method can only be used in the NT cmd environment. |
|
| Floor5 willsort | Posted 2005-08-06 17:50 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re chjlcn:
In a pure DOS environment, there is another method to obtain date variables, which can be found in the code on the 7th floor of {8905} An Oddity in Batch Programming. In addition, if it is to be used as a file or directory name in a system that does not support long filenames (the MSDOS7.10 on this site supports it), you need to pay attention to the number of digits of "year" in the date variable; if it is a 4-digit year, the last two characters of the date variable will be truncated. It may be "05" of 2005, or "06" of 08-06, depending on the system's date format. |
|
| Floor6 chjlcn | Posted 2005-08-07 09:39 |
| 初级用户 Posts 7 Credits 43 From 广东 | |
|
### 首先分析 `echo exit | %comspec% /k prompt set %1=%2$_:: > _GetVar.bat` 这一整句的含义:
- `echo exit`:`echo` 命令用于输出文本,这里输出 `exit` 这个字符串。 - `|`:管道符号,将前面 `echo exit` 的输出作为后面命令的输入。 - `%comspec%`:获取系统的命令行解释器路径,通常是 `cmd.exe`(在 Windows 系统中)。 - `/k`:`%comspec%` 的参数,表示执行完命令后不关闭命令提示符窗口。 - `prompt set %1=%2`:`prompt` 命令在这里被用来设置一个临时的命令,这里的 `%1` 和 `%2` 是脚本的参数,假设脚本调用时传入了两个参数,`%1` 会被替换为第一个参数,`%2` 会被替换为第二个参数,比如如果传入的是 `varName` 和 `varValue`,那么这里就会变成 `prompt set varName=varValue`。 - `$_`:这里 `$_` 应该是用来表示一个换行符,在批处理中可以用 `$_` 来插入一个换行。 - `::`:在批处理中,`::` 后面的内容被视为注释,这里主要是为了让后面的 `>` 重定向到文件时的语法正确。 - `> _GetVar.bat`:将前面通过管道传递过来的内容重定向到名为 `_GetVar.bat` 的文件中。 整体来说,这一句的作用是:通过 `echo` 输出 `exit`,然后利用管道将其作为输入传递给 `%comspec% /k prompt set %1=%2$_::` 命令,最后将这个组合的结果重定向到 `_GetVar.bat` 文件中,从而在这个临时批处理文件中设置了一个基于传入参数的 `prompt` 相关命令。 |
|
| Floor7 Climbing | Posted 2005-08-07 10:48 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Hehe, the key is this sentence! Understand it slowly by yourself. This is the essence in the skills of batch processing.
|
|
| Floor8 chjlcn | Posted 2005-08-07 18:21 |
| 初级用户 Posts 7 Credits 43 From 广东 | |
|
@climbing
Can you give some hints on which commands to learn? Are there any relevant e-books for download? |
|
| Floor9 willsort | Posted 2005-08-08 13:24 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re chjlcn:
To be really detailed, it might be quite complicated because of my limited expression ability. I often can't grasp what the readers already know and what they don't. Maybe in future DOS books, I will write a special article to explain the techniques of this code. Currently, I can only simply provide some ideas to master it: 1. Comment out the for statement that deletes _GetVar.bat, then execute getvar today=$D in the command line to view the content of _GetVar.bat; 2. Remove the redirection part > _GetVar.bat of the echo line, then execute getvar today=$D in the command line to view the output content on the screen; 3. Execute separately in the command line: echo exit | %comspec% /k prompt set today=$D$_:: %comspec% /k prompt set today=$D$_:: prompt set today=$D$_:: Then observe their respective output contents, and I believe you will have some insights. [ Last edited by willsort on 2005-8-8 at 13:26 ] |
|
| Floor10 chjlcn | Posted 2005-08-09 18:03 |
| 初级用户 Posts 7 Credits 43 From 广东 | |
|
I found that %myDate:~0,2% is not supported under DOS. Are there any functions to get some characters from a string?
|
|
| Floor11 Climbing | Posted 2005-08-09 21:35 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Has willsort already provided a solution? Haven't you studied it carefully?
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |