dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.06k stars 4.69k forks source link

Linux: `System.Diagnostics.ProcessStartInfo`: With `UseShellExecute = true`, a misleading exception is thrown when no helper utility (such as `xdg-open`) is present. #96565

Open mklement0 opened 9 months ago

mklement0 commented 9 months ago

Description

On Linux distros, opening a document or folder path via UseShellExecute = true relies on external helper utilities; specifically, the following ones are looked for, via the Path environment variable, in order, with the first one getting used: xdg-open, gnome-open, kfmclient

In the absence of these helper utilities, an exception is thrown, which makes sense, but the exception is misleading, as it reports the .FileName property value as nonexistent.

That is, the nonexistence of a helper utility is mistakenly reported as the the .FileName property value's nonexistence (even if the latter actually exists).

Reproduction Steps

On a Linux distro with none of the helper utilities present (if a helper utility is present, the call should open the current directory GUI shell's file manager):

System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo { FileName = ".", UseShellExecute = true })

Expected behavior

An exception that indicates the absence of a required helper utility.

Actual behavior

E.g. when run from /tmp:

An error occurred trying to start process '.' with working directory '/tmp'. No such file or directory

Regression?

No response

Known Workarounds

No response

Configuration

Other information

No response

ghost commented 9 months ago

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process See info in area-owners.md if you want to be subscribed.

Issue Details
### Description On Linux distros, opening a document or folder path via `UseShellExecute = true` relies on external helper utilities; specifically, the [following ones are looked for, via the `Path` environment variable](https://github.com/dotnet/runtime/blob/9e31c21bcbb661fc4fa235839a66442a65ef447c/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs#L110), in order, with the first one getting used. `xdg-open`, `gnome-open`, `kfmclient` In the absence of these helper utilities, an exception is thrown, which makes sense, but the exception is _misleading_, as it reports the `.FileName` property value as nonexistent. That is, the nonexistence of a _helper utility_ is mistakenly reported as the the `.FileName` property value's nonexistence (even if the latter actually exists). ### Reproduction Steps On a Linux distro with none of the helper utilities present (if a helper utility is present, the call should open the current directory GUI shell's file manager): ```csharp System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo { FileName = ".", UseShellExecute = true }) ``` ### Expected behavior An exception that indicates the absence of a required helper utility. ### Actual behavior E.g. when run from `/tmp`: ```none An error occurred trying to start process '.' with working directory '/tmp'. No such file or directory ``` ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration * .NET 8.0.0 * CBL-Mariner/Linux 2.0 ### Other information _No response_
Author: mklement0
Assignees: -
Labels: `area-System.Diagnostics.Process`, `untriaged`
Milestone: -