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-06 02:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can a batch file open a new window View 1,479 Replies 9
Original Poster Posted 2007-10-06 21:01 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
When running a.bat, I want b.bat to open in a new window. After b.bat finishes running, a.bat should then continue. (I can't use call, because if b.bat runs in the same window, the program in b.bat will stop working)
Floor 2 Posted 2007-10-06 23:20 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Floor 3 Posted 2007-10-07 00:44 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Thanks, moderator!
Opening a new window does work now, but problem 1: the new window can't close automatically. Problem 2: a.bat only continues after pressing n.
Problem 3: the program in b.bat still does not execute (stops working)

Actually, in a.bat I executed once:
cd.>t.txt
for /f "delims=" %%i in (a.txt) do (
if not defined %%i set %%i=A & echo %%i>>t.txt
)

But a bit later I still need to execute this again:
cd.>t2.txt
for /f "delims=" %%k in (a2.txt) do (
if not defined %%k set %%k=B & echo %%k>>t2.txt
)

The problem is: the second execution absolutely refuses to write to t2.txt.
Floor 4 Posted 2007-10-07 02:40 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Floor 5 Posted 2007-10-07 09:12 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Thank you very much, enthusiastic moderator!
Using your start /wait cmd /c b.bat really did solve problem 1, the new window not closing automatically, and problem 2, a.bat only continuing after pressing n.
But problem 3, the program in b.bat still not executing (stopping working), still has not been solved. I don't know why.
At first I put
cd.>t.txt
for /f "delims=" %%i in (a.txt) do (
if not defined %%i set %%i=A & echo %%i>>t.txt
)
and
cd.>t2.txt
for /f "delims=" %%k in (a2.txt) do (
if not defined %%k set %%k=B & echo %%k>>t2.txt
)
in the same bat for execution, and found that it would not write data to t2.txt. Later I split them into a.bat and b.bat,
and after running a.bat and then b.bat, both executed normally, which is why I asked my original question. Now the problem of not writing data to t2.txt is still not solved.
Floor 6 Posted 2007-10-07 18:33 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
I tested it separately yesterday. I simulated your program, wrote data, and there was no problem.

Maybe there is something wrong with your program. Post it and let us take a look.

Also, multiple bat files can all be integrated into one bat for execution, there's no need to split them into several.
Floor 7 Posted 2007-10-07 21:10 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Floor 8 Posted 2007-10-07 23:04 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Floor 9 Posted 2007-10-07 23:19 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
A solution has already been given in the batch file section, you can refer to it.
Floor 10 Posted 2007-10-08 11:12 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Many thanks to Mr. lxmxn!
Your setlocal and endlocal commands solved the problem of having
cd.>t.txt
for /f "delims=" %%i in (a.txt) do (
if not defined %%i set %%i=A & echo %%i>>t.txt
)
and
cd.>t2.txt
for /f "delims=" %%k in (a2.txt) do (
if not defined %%k set %%k=B & echo %%k>>t2.txt
)
in the same program.
Thanks again!!
But it still did not solve the problem in the program I posted.
However, it already solved more than half of it for me. Using your setlocal and endlocal commands, I made
structural adjustments to the original program, removed one step, and achieved what I wanted.
Thanks again!!
2007.10.08.11
Forum Jump: