@echo off
color 06
title created by AAIE
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco install youtube-dl
set /p input="Enter Link For Playlist:"
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
我如何檢查 choco 或 youtube_dl 是否安裝在 windows 中或主要問題我需要檢查它是否為真的條件是什么然后如果沒有安裝則直接使用命令然后它將安裝它們并使用相同的命令
uj5u.com熱心網友回復:
以下是一些where用于根據結果定位和執行操作的示例:
@echo off
(where choco.exe)>nul 2>&1
if errorlevel 1 (
echo Choco not installed. Installing now..
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)
choco install youtube-dl
set /p input="Enter Link For Playlist:"
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
或使用條件運算子:
@echo off
(where choco.exe)>nul 2>&1 && goto :installed || goto :install
:install
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
:installed
choco install youtube-dl
set /p input="Enter Link For Playlist:"
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
請注意,這些是簡單的示例,沒有內置錯誤處理,例如 coco 安裝失敗時會發生什么等。
根據你的問題 2>&1 >nul
stdout(視為1>重定向時)是命令的輸出流,其中stderr(視為2>重定向時。)
在執行>nul或> file.txt我們有效地將命令的輸出重定向到nul(在控制臺上看不到)或檔案(記錄目的)時,但stdout默認情況下并非所有內容都進入流。所以我們需要將 stderr 流重定向到 stdout,然后重定向stdout到nul一個檔案。
您顯然也可以獨立重定向。
commandname 1>out.log 2>error.log
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/372731.html
