关闭.txt文件后关闭控制台

时间:2018-03-27 18:52:43

标签: windows file cmd command

我制作了一个简单的脚本,将磁盘结构保存到.txt文件,然后打开它。关闭.txt文件后,有没有办法自动关闭控制台?

这是我的代码的样子。 variables.cmd包含我的所有变量声明。

@echo off

call "%~dp0\variables.cmd" /b

%disk%:
cd /

echo Creating folders

md %loc_a%
md %loc_b%
md %loc_c%
md %lok_d%
md %loc_e%
md %loc_f% 

echo Folders created
echo %name% > %name%\%aa%_1.txt
echo %aa% > %lokalizacja_a%\%bb%_2.txt
echo %bb% > %lokalizacja_b%\%cc%_3.txt
echo %cc% > %lokalizacja_c%\%dd%_4.txt
echo %dd% > %lokalizacja_d%\%ee%_5.txt
echo %ee% > %lokalizacja_e%\%ff%_6.txt
echo %ff% > %lokalizacja_f%\%gg%_7.txt

cd %name%

set fileone= %aa%_1.txt


copy %icon1% %icon2%


echo [.ShellClassInfo] > %loc_a%\desktop.ini
echo IconFile=%dysk%:\%ikona2% >> %loc_a%\desktop.ini
echo IconIndex = 0 >> %loc_a%\desktop.ini
attrib +h +r -a &loc_a%\desktop.ini
attrib +r %loc_a%

start %name%\%aa%_1.txt

pause


rem I want to close this after I close %pause%\%aa%_1.txt 

2 个答案:

答案 0 :(得分:0)

替换:

start %name%\%aa%_1.txt
pause

使用:

start /wait %name%\%aa%_1.txt
REM No need for pause, as you want the script to exit when text is closed.

答案 1 :(得分:0)

好问题!!

CMD

使用exit命令关闭控制台

PowerShell

您只需

即可关闭控制台

stop-process -Id $PID

控制台会自动检测ProcessID并关闭进程。

P.S:exit,exit(1)和exit(0)等退出函数将阻止脚本运行。

=============================================== ==========