Batch file 批处理文件中的Powershell命令未按预期工作
我正在运行一个批处理脚本,但我得到了一个错误声明Batch file 批处理文件中的Powershell命令未按预期工作,batch-file,powershell-1.0,Batch File,Powershell 1.0,我正在运行一个批处理脚本,但我得到了一个错误声明 -命令未被识别为内部或外部命令、可操作程序或批处理文件 我不明白为什么。我还查看了我的环境变量路径。看起来不错 下面是脚本 @echo off set PWSH = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe %PWSH% -command $input ^| %1\post-commit-jenkins.ps1 %1 %2 pause if errorleve
-命令未被识别为内部或外部命令、可操作程序或批处理文件
我不明白为什么。我还查看了我的环境变量路径。看起来不错
下面是脚本
@echo off
set PWSH = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| %1\post-commit-jenkins.ps1 %1 %2
pause
if errorlevel 1 exit %errorlevel%
请提供您的意见和可能的解决方案
@echo off
set "PWSH=%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
%PWSH% -command $input ^| %1\post-commit-jenkins.ps1 %1 %2
pause
if errorlevel 1 exit %errorlevel%
设置a时请删除空格,否则它将是变量名的一部分(不是我不知道%1和%2参数是什么,所以我不知道以后会发生什么)Npcmaka已经提供了解决方案,但为了解释原因:
%PWSH%
是空的,因为您定义的变量是%PWSH%
。删除Echo off
以观看…如果您能解释一下您希望执行的操作,可能会有所帮助%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe-command$input^ |%1\post-commit-jenkins.ps1%1%2
!现在您是否正在使用Powershell版本1非常值得怀疑。