question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The automatic windows parameter doesn't work for powershell scripts

See original GitHub issue

Version(s)

10.0.0

To reproduce

Steps to reproduce the behaviour:

  1. Add a SimpleExec.RunAsync(“myscript.ps1”).
  2. Execute
  3. 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:closed
  • Created a year ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mockjvcommented, May 16, 2022

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

1reaction
adamralphcommented, May 15, 2022

it looks like your considering re-introducing that argument

@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 ps1 is not treated as “executable” in Windows. The only way to “execute” a ps1 file in Windows is to pass it as an argument to powershell.exe (or rely on file extension association to do that for you). So when using SimpleExec to execute a ps1 file, the correct way to do that is:

await RunAsync("powershell", "foo.ps1 bar baz");

If you are running something else on Linux or macOS then you need make your code conditional on the OS. E.g.

await Command.RunAsync(
    RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "powershell" : "foo",
    $"{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "foo.ps1" : "")} bar baz");

I acknowledge that you were using the windowsName and windowsArgs parameters for this purpose before:

await Command.RunAsync("foo", "bar baz",
    windowsName: "powershell",
    windowsArgs: "foo.ps1 bar baz");

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 the args and windowsArgs parameters, and therefore I’m not convinced it’s worth maintaining that more complex API in SimpleExec for this purpose.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found