Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias error with Exec on Linux #328

Open
paulhey opened this issue Dec 1, 2022 · 0 comments
Open

Alias error with Exec on Linux #328

paulhey opened this issue Dec 1, 2022 · 0 comments

Comments

@paulhey
Copy link

paulhey commented Dec 1, 2022

While doing Powershell development on Linux I encountered an issue running a psakefile.ps1.
The component:

...
Task GitPull {
  Exec { git pull }
}
...

Expected Behavior

❯ invoke-psake GitPull
psake version 4.9.0
Copyright (c) 2010-2018 James Kovacs & Contributors

Executing GitPull
Already up to date.

psake succeeded executing psakefile.ps1

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name    Duration
----    --------
GitPull 00:00:01.370
Total:  00:00:01.385

Current Behavior

❯ invoke-psake GitPull
psake version 4.9.0
Copyright (c) 2010-2018 James Kovacs & Contributors

Executing GitPull
Error: 2022-12-01 1:24:56 p.m.: 
At /home/paulhey/Projects/labcollector/psakefile.ps1:377 char:3 +   Exec { git pull } +   ~~~~~~~~~~~~~~~~~ [<<==>>] Exception: Command '' was not found. The specified command must be an executable.

Possible Solution

Current work around is to remove the alias so I can continue to run the script.

❯ Remove-Alias exec

Or add this line to your Profile script

Steps to Reproduce (for bugs)

  1. Install Powershell 7.3.0
  2. Install psake powershell module (4.9.0)
  3. Create a psakefile.ps1 with an Exec statement in it
  4. Run the Invoke-PSake against the task with the Exec statement

Context

I was attempting to use my psakefile to handle some automation steps. After the error was thrown I had though there was an issue with my psakefile (typo, etc) and so I opened it up into VSCode where I discovered that it was reporting Exec as an alias for Switch-Process (I found this online documentation). I may also have to open an issue with PSScriptAnalyzer or VSCode-PowerShell as the analyzer reports it as an alias instead of a function and the formatting tool wants to replace it as such.
So with some additional troubleshooting, I am unable to reproduce this in PowerShell 7.2.* and with a bit of digging I found a PR on the main PowerShell repo for PowerShell 7.3.1, which looks to create a colliding function instead of an alias.

I have been unable to reproduce in Windows, as the alias Exec and function Switch-Process don't exist there.

Your Environment

  • Module version used:
❯ Get-Module psake        

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     4.9.0                 psake                               {Assert, Exec, FormatTaskName, Framework…}
  • Operating System and PowerShell version:
❯ $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Linux 6.0.6-76060006-generic #202210290932~1669062050~22.04~d94609a SMP PREEMPT_DYNAMIC Mon N
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant