Abhishek Kumar
Abhishek Kumar

Reputation: 352

Powershell command from batch file not working as expected

I am running a batch script, but I get an error stating that

-command is not recognized as internal or external command, operable program or batch file

I am not able to understand why. I also looked at my environmental variable path. That looks to be fine.

Below is the Script

@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%  

Please provide your opinion and possible solution .

Upvotes: 1

Views: 1469

Answers (1)

npocmaka
npocmaka

Reputation: 57252

@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% 

Remove the space when you are setting a otherwise because it will be part of the variable name (not I have no idea what are the %1 and %2 arguments so I don't know what to expect further )

Upvotes: 1

Related Questions