我正在尝试将goto和if then命令放在同一行中,因为所以我不必再制作另一个BAT文件来完成工作。 这是我到目前为止所做的代码示例:
@echo on
START "taskkilling and cliping" CMD /c "@echo off & echo|set /p=username@email.com|clip & TASKKILL /F /T /IM Greenshot.exe & TASKKILL /F /T /IM iprntctl.exe & TASKKILL /F /T /IM iprntlgn.exe & TASKKILL /F /T /IM smax4pnp.exe & TASKKILL /F /T /IM ZenNotifyIcon.exe & TASKKILL /F /T /IM ZenUserDaemon.exe & TASKKILL /F /T /IM RAVBg64.exe & TASKKILL /F /T /IM nwtray.exe & TASKKILL /F /T /IM RtkNGUI64.exe & TASKKILL /F /T /IM BingSvc.exe & TASKKILL /F /T /IM Spotify.exe & TASKKILL /F /T /IM SpotifyWebHelper.exe & TASKKILL /F /T /IM FacebookGameroom.exe & TASKKILL /F /T /IM "Facebook Gameroom Browser.exe" & TASKKILL /F /T /IM zapp.exe & TASKKILL /F /T /IM steamwebhelper.exe & TASKKILL /F /T /IM Steam.exe & TASKKILL /F /T /IM lync.exe"
START "start new firefox in three new tabs" CMD /c "@echo off & CD /D "C:\Program Files (x86)\Mozilla Firefox" & firefox.exe "https://www.outlook.com/" "http://everybodyedits.com/" "http://www.kongregate.com/accounts/username/recently-played""
Whcih用于此BAT文件: 老版本
SET _startffox=0
CHOICE /C wt /m "w open new window, t open new tab"
IF errorlevel 2 set _startffox=0 & goto line
IF errorlevel 1 set _startffox=1 & goto line
:line
pause & echo %_startffox%
(echo on & (If "%_startffox%"=="1" goto newwindow); (If "%_startffox%"=="0" goto newtab); (:newwindow & ECHO "go to new window firefox" & ECHO "Hi windows" & pause & EXIT); (:newtab & ECHO "go to new tabs firefox" & ECHO "Hi tabs" & pause & EXIT))
pause
所以我正在尝试制作一个BAT文件,其中包含我可以用于我登录计算机时使用的新版本的选项。 到目前为止,我尝试通过不同的BAT文件测试其中一个代码,所以到目前为止我所拥有的是:
import { Injectable } from '@angular/core';
@Injectable()
export class TaskService {
private tasklist= [{taskname:"sample task",taskdetail:"This is a test task",status:"todo"}];
constructor() { }
getTasklist(chosenstatus){
return this.tasklist.filter((e)=>{
if(e.status==chosenstatus){
return e;
}
});
}
addTask(name,task){
console.log(this.tasklist);/*this shows new task added*/
this.tasklist.push({taskname:name,taskdetail:task,status:"todo"});
}
}
到目前为止,它不像我工作的方式那样有效。
答案 0 :(得分:0)
@echo off
setlocal
SET "_cliportaskkill=0"
SET "_startffox=0"
If "%_cliportaskkill%"=="2" call :everything
If "%_cliportaskkill%"=="1" call :cliponly
If "%_cliportaskkill%"=="0" call :taskkillonly
If "%_startffox%"=="1" call :newwindow
If "%_startffox%"=="0" call :newtab
EXIT /B
:cliponly
echo|set /p=username@email.com|clip
EXIT /B
:taskkillonly
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:everything
echo|set /p=username@email.com|clip
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:newwindow
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
"https://www.outlook.com/"^
"http://everybodyedits.com/"^
"http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
:newtab
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
-new-tab "https://www.outlook.com/"^
-new-tab "http://everybodyedits.com/"^
-new-tab "http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
你能把goto放进一行吗?
是
标签虽然需要在一行的开头,但可以在之前 用于缩进的空格。
建议您在许多情况下使用call
代替goto
当call
转到标签然后返回时,给出良好的程序流程
回到来电者的路线。使用goto
转到标签和
然后你可能需要再次使用goto
去其他地方
你全身心投入,最终可能会迷失方向。所以使用call
允许将所有主要代码组合在一起并将标签称为
需要的。
taskkill
可以在一个过程中处理多个图像
效率更高。
使用^
将命令继续到下一行以排列
垂直参数。可以提高可读性和维护性。
使用EXIT /B
可以退出标签或脚本。
使用EXIT
会关闭通常不受欢迎的解释器
对于剧本。
可以使用CHOICE
或任何其他新想法自由更新代码
你可能有。
缩进标签示例。
@echo off
if not "%~1" == "" call :level0 %*
exit /b
:level0
echo test indented label
:level1
echo "%~1"
shift
if not "%~1" == "" goto :level1
echo done
exit /b
使用参数main.cmd 1 2 3
调用示例脚本。解释器会找到:level1
,即使它是缩进的。
答案 1 :(得分:0)
仍然没有弄清楚如何放入一行并更新michael_heath代码与我的一点点:
@echo on
setlocal
CHOICE /C ectfx /m "e do everything, c clip only, t taskkill only, f skip this, x close this"
If errorlevel 5 EXIT /B
If errorlevel 4 goto :choiceff
If errorlevel 3 call :taskkillonly
If errorlevel 2 call :cliponly
If errorlevel 1 call :everything
:choiceff
CHOICE /C wtx /m "w open new window, t open new tab, x close this"
If errorlevel 3 EXIT /B
If errorlevel 2 call :newtab
If errorlevel 1 call :newwindow
EXIT /B
:cliponly
echo|set /p=username@email.com|clip
EXIT /B
:taskkillonly
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:everything
echo|set /p=username@email.com|clip
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:newwindow
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
"https://www.outlook.com/"^
"http://everybodyedits.com/"^
"http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
:newtab
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
-new-tab "https://www.outlook.com/"^
-new-tab "http://everybodyedits.com/"^
-new-tab "http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
从代码中删除VAR cliportaskkill
和startffox
以及一个小问题,只有在完成代码后才按t转到taskkill,它会转到下一个错误级别并调用:cliponly
代码在它转到下一个选择命令之前(这里我放了一个& goto :label
来阻止这个bug,但是当放入一行时可能会破坏这个BAT文件。)
PS 在不久的将来,我想我可以重新放入cliportaskkill
和startffox
VAR,以便我可以将它用于并行代码或两个实例而无需等待其他代码完成(也没有在另一个BAT文件中完成。)
我将echo设置为on和这里代码的输出。
>setlocal
>CHOICE /C ectfx /m "e do everything, c clip only, t taskkill only, f skip this, x close this"
e do everything, c clip only, t taskkill only, f skip this, x close this [E,C,T,F,X]?T
>If errorlevel 5 EXIT /B
>If errorlevel 4 goto :choiceff
>If errorlevel 3 call :taskkillonly
>TASKKILL /F /T /IM Greenshot.exe /IM iprntctl.exe /IM iprntlgn.exe /IM smax4pnp.exe /IM ZenNotifyIcon.ex
e /IM ZenUserDaemon.exe /IM RAVBg64.exe /IM nwtray.exe /IM RtkNGUI64.exe /IM BingSvc.exe /IM Spotify.exe /IM SpotifyWebHelper.exe /IM F
acebookGameroom.exe /IM "Facebook Gameroom Browser.exe" /IM zapp.exe /IM steamwebhelper.exe /IM Steam.exe /IM lync.exe
ERROR: The process "Greenshot.exe" not found.
ERROR: The process "iprntctl.exe" not found.
ERROR: The process "iprntlgn.exe" not found.
ERROR: The process "smax4pnp.exe" not found.
ERROR: The process "ZenNotifyIcon.exe" not found.
ERROR: The process "ZenUserDaemon.exe" not found.
ERROR: The process "RAVBg64.exe" not found.
ERROR: The process "nwtray.exe" not found.
ERROR: The process "RtkNGUI64.exe" not found.
ERROR: The process "BingSvc.exe" not found.
ERROR: The process "Spotify.exe" not found.
ERROR: The process "SpotifyWebHelper.exe" not found.
ERROR: The process "FacebookGameroom.exe" not found.
ERROR: The process "Facebook Gameroom Browser.exe" not found.
ERROR: The process "zapp.exe" not found.
ERROR: The process "steamwebhelper.exe" not found.
ERROR: The process "Steam.exe" not found.
ERROR: The process "lync.exe" not found.
>EXIT /B
>If errorlevel 2 call :cliponly
>echo | set /p=username@email.com | clip
>EXIT /B
>If errorlevel 1 call :everything
>CHOICE /C wtx /m "w open new window, t open new tab, x close this"
w open new window, t open new tab, x close this [W,T,X]?
正如你在taskkill块之后看到的那样,在进入下一个CHOICE
命令之前,它会进入下一个阻塞代码块(由于某种原因,它不会转到下一个代码块。)< / p>
我已经按了T这个
>If errorlevel 3 EXIT /B
>If errorlevel 2 call :newtab
>CD /D "C:\Program Files (x86)\Mozilla Firefox"
>firefox.exe -new-tab "https://www.outlook.com/" -new-tab "http://everybodyedits.com/" -new-tab "
http://www.kongregate.com/accounts/username/recently-played"
>ECHO newtab!
newtab!
>pause
Press any key to continue . . .
>EXIT /B
>If errorlevel 1 call :newwindow
>CD /D "C:\Program Files (x86)\Mozilla Firefox"
>firefox.exe "https://www.outlook.com/" "http://everybodyedits.com/" "http://www.kongregate.com/a
ccounts/username/recently-played"
>ECHO newwindow!
newwindow!
>pause
Press any key to continue . . .
我添加了echo
和pause
来测试它是否对此CHOICE
命令执行相同操作,并在完成上一个代码后启动下一个代码块。我在测试文件中对此进行了测试,其中我使用了一些CHOICE,如果错误级别,调用和goto命令以及测试文件中发生了相同的错误。