China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 12:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems in making batch processing for ghost continuous backup of three partitions View 1,771 Replies 10
Original Poster Posted 2005-08-05 08:16 ·  中国 广东 江门 新会区 电信
初级用户
Credits 43
Posts 7
Joined 2005-08-05 08:15
20-year member
UID 41357
Gender Male
From 广东
Status Offline
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?
Floor 2 Posted 2005-08-05 09:05 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-08-05 15:47 ·  中国 广东 江门 新会区 电信
初级用户
Credits 43
Posts 7
Joined 2005-08-05 08:15
20-year member
UID 41357
Gender Male
From 广东
Status Offline
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.
Floor 4 Posted 2005-08-05 16:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2005-08-06 17:50 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2005-08-07 09:39 ·  中国 广东 江门 新会区 电信
初级用户
Credits 43
Posts 7
Joined 2005-08-05 08:15
20-year member
UID 41357
Gender Male
From 广东
Status Offline
### 首先分析 `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` 相关命令。
Floor 7 Posted 2005-08-07 10:48 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Hehe, the key is this sentence! Understand it slowly by yourself. This is the essence in the skills of batch processing.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 8 Posted 2005-08-07 18:21 ·  中国 广东 江门 新会区 电信
初级用户
Credits 43
Posts 7
Joined 2005-08-05 08:15
20-year member
UID 41357
Gender Male
From 广东
Status Offline
@climbing

Can you give some hints on which commands to learn?
Are there any relevant e-books for download?
Floor 9 Posted 2005-08-08 13:24 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 10 Posted 2005-08-09 18:03 ·  中国 广东 江门 台山市 电信
初级用户
Credits 43
Posts 7
Joined 2005-08-05 08:15
20-year member
UID 41357
Gender Male
From 广东
Status Offline
I found that %myDate:~0,2% is not supported under DOS. Are there any functions to get some characters from a string?
Floor 11 Posted 2005-08-09 21:35 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Has willsort already provided a solution? Haven't you studied it carefully?
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Forum Jump: