Runtime: UseShellExecute cause exception on linux

Created on 10 Jul 2018  路  8Comments  路  Source: dotnet/runtime

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.

area-System.Diagnostics.Process bug os-linux

All 8 comments

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

  • Could you copy & paste as little code as possible to show the exception?
  • Could you copy & paste the whole exception message?
  • What is the output of dotnet --info on the computer where app was built?
  • What is the output of dotnet --info on the computer where app was run?
  • How was the app built/published? (please share the command line)
  • What binaries were copied on the machine where the app was executed?

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 -c Release -r centos.7-x64

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iCodeWebApps picture iCodeWebApps  路  3Comments

yahorsi picture yahorsi  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments

bencz picture bencz  路  3Comments

omariom picture omariom  路  3Comments