Powershell not working correctly with pipe "|" using GitHub Actions

Hi,

I have a powershell script that has this command in it:

echo mypassword | p4 login

The command passes in the password mypassword to the p4 login command. This command is how I login to a Perforce server.

My GHA workflow just pulls down the repo that contains the powershell script and runs it.

When I run the same script via GHA it fails, it says the password is invalid.

I logged onto my self-hosted GHA runner and looked at the cloned repo that GHA had pulled down, the powershell script is fine, I can even run the cloned repo manually on the GHA runner and it works.

I also tried like this and it works - which I think is how GHA sort of runs it:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command "D:\actions-runner\_work\hgrs-HeightsAndAngles-perforce-sync-onprem\hgrs-HeightsAndAngles-perforce-sync-onprem\src\sync_game.ps1"

I then tried to run the command directly in the GHA pipeline YAML, rather than from the script. But then I get the same error about the invalid password.

It seems that GHA mangles the command somehow when it runs it, whether via the pipeline YAML or running the script via powershell on the server.

I think it may be related to this:

especially as GHA runner it a fork of the Azure DevOps agent…