[英]How to open Powershell with cmd and use a .ps1 file
我嘗試打開一個 ps1 powershell 文件,它更新了一個 gitrepo
我試過了
powershell -ExecutionPolicy Bypass -Command "& '%USERPROFILE%\folder1\update.ps1'
這是有效的,但是當涉及到 requirements.txt 時,promt 會寫入未找到該文件的錯誤,我認為 powershell 不直接在此文件夾中,因此無法找到所需的文件
如果我做這個
cd %USERPROFILE%\ & REM First change to the batch file folder
echo Points as at = %time% %date%> updatebing_log.txt & REM create a simple logfile with time and end result of the batch run
echo ============================folder1=========================== >> updatebing_log.txt
cd folder1\
start powershell
cd %USERPROFILE%\folder1
powershell -ExecutionPolicy Bypass -Command "& '%USERPROFILE%\folder1\update.ps1'
echo Waiting seconds
timeout /t 10 /nobreak > NUL
它正在工作,但它打開一個 cmd(bash 文件)promt 和一個 powershell 然后它 cd 到文件夾 powershell 什么都不做然后在 cmd 里面我看到 ps1 文件被執行並且也可以使用 requirements.txt
根據我的評論。 這是您的代碼正在執行的操作。 因此,您看到的響應。
# Run this in cmd.exe
cd %USERPROFILE%\ & REM First change to the batch file folder
echo Points as at = %time% %date%> updatebing_log.txt & REM create a simple logfile with time and end result of the batch run
echo ============================folder1=========================== >> updatebing_log.txt
cd folder1\
# Start a PowerShell interactive session
start powershell
cd %USERPROFILE%\folder1
# Start a new PowerShell session from cmd.exe and run this code
powershell -ExecutionPolicy Bypass -Command "& "$env:USERPROFILE\folder1\update.ps1" # note the profile change I made for you.
# Run this in cmd.exe on Powerhell exit
echo Waiting seconds
timeout /t 10 /nobreak > NUL
如果那不是您想要的流程,那么您需要重新考慮這一點。
我在工作中做了這個它看起來像它工作但不知道我嘗試顯示工作目錄但它想要顯示它只顯示 ps1 調用文件是
我做了一個test.bat
powershell -ExecutionPolicy Bypass -Command "& '%USERPROFILE%\Brewd\updatebrewdall.ps1'"
和 updatecall.ps1
cd "folder1\"
powershell -ExecutionPolicy Bypass -Command "& '.\update.ps1'"
Start-Sleep -Seconds 10
# now back to previous directory
cd ..\
cd "folder2\"
"$([Environment]::CurrentDirectory)\$ComputerName"
powershell -ExecutionPolicy Bypass -Command "& '.\update.ps1'"
Start-Sleep -Seconds 10
# now back to previous directory
cd ..\
cd "folder3\"
"$([Environment]::CurrentDirectory)\$ComputerName"
powershell -ExecutionPolicy Bypass -Command "& '.\update.ps1'"
Start-Sleep -Seconds 10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.