The automatic windows parameter doesn't work for powershell scripts
See original GitHub issueVersion(s)
10.0.0
To reproduce
Steps to reproduce the behaviour:
- Add a SimpleExec.RunAsync(“myscript.ps1”).
- Execute
- Observe failure “An error occurred trying to execute”
Expected behaviour
I would loosely expect this new automatic behavior to play nice with ps1 files, and possibly other windows scripting files (e.g., vbs, js)?
Actual behaviour
System.ComponentModel.Win32Exception (193): An error occurred trying to start process 'C:\0\repos\LRS-CSharp-Build\src\LRS.CSharp.Build\tools\win32\bin\dotnet-install.ps1' with working directory 'C:\0\repos\LRS-CSharp-Build'. The specified executable is not a valid application for this OS platform.
Workarounds
Add a wrapper if/else to make the main executable powershell.exe, which was technically possible when windowsName was available but now that it isn’t I have to add my own if block.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Powershell script not working through Task Scheduler
In the Scheduler I found that the Task starts and finishes but the script does not run. I even added the command below...
Read more >Why won't this powershell script accept parameters?
I'm simply trying to work with Powershell parameters in CMD, and I can't seem to get a script to take one. I see...
Read more >How to pass needed parameters to script in Powershell ISE?
Use the command pane. Open the script file in the ISE editor, set the breakpoints (F9). Then in the command pane type a...
Read more >Understanding Windows PowerShell function parameters
Learn to use Windows PowerShell function parameters, with information on defining parameters; named, positional and switch parameters; ...
Read more >Is there a way to supress any interactive prompts in a ...
None : Windows PowerShell does not prompt automatically. To request confirmation of a particular command, use the Confirm parameter of the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@adamralph Ok, sorry for the confusion. I could have sworn I’d seen a commit where changes were reverted but I must be losing my mind or I was looking at the wrong thing. I completely understand your concerns regarding the added complexity in your library, so no worries here!
@mockjv as I said in my previous comment (to which you reacted with 👍), I’m leaning towards not providing any special in SimpleExec here, and leaving it to the caller to make the command name and args conditional on the OS, etc.
Note that
ps1is not treated as “executable” in Windows. The only way to “execute” aps1file in Windows is to pass it as an argument topowershell.exe(or rely on file extension association to do that for you). So when using SimpleExec to execute aps1file, the correct way to do that is:If you are running something else on Linux or macOS then you need make your code conditional on the OS. E.g.
I acknowledge that you were using the
windowsNameandwindowsArgsparameters for this purpose before:But I’m not convinced that code is much nicer, not least because you have to pass the “non-script” arguments
"bar baz"to both theargsandwindowsArgsparameters, and therefore I’m not convinced it’s worth maintaining that more complex API in SimpleExec for this purpose.