Repository navigation
Closed
Labels
Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtime
Description
It appears that trying to run jobs inside hosted PowerShell Core from a .NET Core 2.0 app fails.
This was first noticed in Jaykul/Jupyter-PowerShell#20 But I was able to coble together a simple repro https://github.com/markekraus/TesthostedPSJobs
Joel Bennett (@Jaykul) suggested I try and copy the pwsh binary to the hosted app location, but that doesn't seem to work either.
Steps to reproduce
git clone https://github.com/markekraus/TesthostedPSJobs.git
push-location TesthostedPSJobs
dotnet runExpected behavior
No output
Actual behavior
Error: [localhost] An error occurred while starting the background process. Error reported: The system cannot find the file specified.
Exception: System.Management.Automation.Remoting.PSRemotingTransportException: An error occurred while starting the background process. Error reported: The system cannot find the file specified. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
--- End of inner exception stack trace ---
InnerException: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
InnerException:
--------------------------------------------------------
Environment data
Windows 10 x64 (I have not verified this on other OSes)
6.0.2
Reacted by Chris Magnuson and gaelcolas
Metadata
Metadata
Assignees
Labels
Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtime
Activity
BrucePay commentedon Jun 13, 2018
Mark Kraus (@markekraus)
Start-Joblooks forpwsh.exeusingtypeof(PSObject).Assembly.Location. Basically it expects to findpwsh.exein the same directory asSystem.Management.Automation.dll. Perhaps we need an alternate mechanism for looking up what executable to launch.markekraus commentedon Jun 13, 2018
Bruce Payette (@BrucePay) After copying the pwsh.exe to the publish folder
Looking at this from a self contain app, how would you ship this and make it work?
edit: it looks like if I take the exe and dll from my project and drop it in the PowerShell install folder... it works... but that is a really odd way to go about shipping a hosted app that supports jobs...
BrucePay commentedon Jun 13, 2018
Rather than copying stuff into the applications directory. I'd suggest that we have a more flexible way of finding
pwsh.exelike using an environment variable or a configuration file (or the path?). Even within PowerShell Core itself, we should be able to start Windows PowerShell jobs from PowerShell Core but currently we can't because of the hard-coding (see #7059)markekraus commentedon Jun 14, 2018
Bruce Payette (@BrucePay) But if we used pwsh.exe from the path.. that would mean when I build my app it would include the .NET Core and PS libraries... and then I would also need to ship the entire pwsh with it.. which would also include all the .NET Core and PS libraries. basically, to have jobs working in hosted PowerShell Core I would need to double up on PowerShell libraries.
Unlike .NET Framework, in .NET Core when you publish an app all the DLLs for the framework and PowerShell go with it.
daxian-dbw commentedon Nov 15, 2021
The PowerShell Job requires pwsh to be installed, and thus it doesn't work for an application that hosts PowerShell. The recommendation is to use ThreadJob instead.