if in ProcessStartInfo (system.Diagnostic) UseShellExecute is set to true on linux process start cause the following exception: No such file or directory win32 exception at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
process start called in Kestrel webserver's request handler, this process should execute script and set linux specific permissions.
operating system: Cent OS 7 (executed the published application)
dotnet core version 2.1.300
workaround:
if UseShellExecute doesn't set, it solve the problem.
@tamasVajda can you reproduce the problem with any script, also outside of ASP.NET Core in HelloWorld style .NET Core app?
@tamasVajda unfortunately current info might be too little to get a repro. Could you help us answering following questions?
dotnet --info on the computer where app was built?dotnet --info on the computer where app was run?this process should execute script
If you execute a script (like a bash script which has the executable flag set) using Process, UseShellExecute should be set to false.
UseShellExecute is meant to let the OS shell figure out what program to start for the filename. For example, FileName is http://www.dot.net and the _OS shell_ starts a browser.
@krwq :
code:
public void RunSript(string shellname, string workingDir, string arguments = "")
{
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = shellname,
Arguments = arguments,
UseShellExecute = true,
CreateNoWindow = true,
ErrorDialog = false,
WorkingDirectory = workingDir
}
};
process.Start();
}
caling this via:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
RunSript("/usr/bin/sudo", installPath, "chmod a+x " + scriptPath);
}
exception:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLF738C44EUS", Request id "0HLF738C44EUS:00000003": An unhandled exception was thrown by the application.
System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
dotnet --info Output:
1.0.4 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.100-preview-007363 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk].NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Micro
soft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNe
tCore.All]
Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Micro
soft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNe
tCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]
Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETC
ore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
On Server isn't any dotnet core insztalled, we execute it with published version.
Publishing:
dotnet publis
we copie the whole content of publich folder to the remote machine.
@tmds:
Thank for the informations, but why changed hat ebehavior of dotnet 2.0 and dotnet 2.1? in dotnet 2.0 there wasn't any exception (but maybe this useshelexecute was ignored) and why throw it file not found in this case? Not suppoerted or similar exception would be more understandable.
With UseShellExecute on Linux, it tries to find one of these programs:
https://github.com/dotnet/corefx/blob/e0ba7aa8026280ee3571179cc06431baf1dfaaac/src/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs#L106
when no program is found it throws here:
https://github.com/dotnet/corefx/blob/a060c9669865f0089e293360deb44941f441d238/src/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs#L314-L317
why changed hat ebehavior of dotnet 2.0 and dotnet 2.1?
For 2.0 this was the behavior:
It was changed here: https://github.com/dotnet/corefx/pull/23705
when no program is found it throws here
Rather than throwing, should we fall back to just using sh as was done in 2.0?
Rather than throwing, should we fall back to just using sh as was done in 2.0?
The behavior would change based on the the installed applications (xdg-open, ...), which is not good.
If one of the apps is installed, it would open up the script in an editor.
If none of the apps is installed, it would execute the script.