Runtime: Check if we can open the directory on Linux when UseShellExecute is set

Created on 12 Sep 2017  路  9Comments  路  Source: dotnet/runtime

I am creating this issue to track if we can open the directory on Linux when having ShellExecute is set.

  • Ideally we would want to throw exception only when UseShellExecute option was false.聽

  • In OSX, the program "open" successfully opens folder using "finder".

  • But Linux needs extra effort to be able to open a folder here. In Linux, xdg-open cannot open folder, so I decided to throw when startInfo.FileName is a directory, regardless of UseShellExecute option being true or false.聽
    Probably the failure happens when the OS doesnt have the installed libraries to open.
    The current behavior in Linux is captured here

Part of this goal is to keep a consistent behavior with Windows.

  • When UseShellExecute is set on windows desktop, Process Start opens directory using File Explorer.

  • Also, the current behavior in Windows running on .NET Core is captured here

Code Sample:

var startInfo = new ProcessStartInfo { UseShellExecute = true, FileName = Environment.CurrentDirectory };
                using (var px = Process.Start(startInfo)) { ... }

@tarekgh

area-System.Diagnostics.Process enhancement os-linux up-for-grabs

Most helpful comment

After thinking about it, I believe xdg-open does officially support to open directories. The man page says xdg-open opens a file or URL in the user's preferred application. For unixoid operating systems, directories are just "special files". From Wikipedia: The most common special file is the directory.

The manpage of xdg-open does not mention anything about only supporting regular files or forbidding special files or directories, so I think opening directories via xdg-open should be fine.

All 9 comments

Hmm, getting the "open a folder" functionality will be decidedly trickier. I guess the method would be different for each desktop environment (if one is even running). I know that Ubuntu, and I guess GNOME systems as well, use the "nautilus" application for the default file browser. You can run nautilus <path> to open a browser at the given folder. I suppose there are ways to detect which desktop environment is being used, but I'm definitely not an expert in that.

Moreover, Windows running on .NET Core has the following behavior:
1-When UseShellExecute is set: throws PlatformNotSupportedException with message "UseShellExecute must always be set to false"

You must have accidentally tried this on 1.x. On 2.0, .NET Core fully supports UseShellExecute on Windows, and it will pop explorer with the folder.

But In Linux, xdg-open cannot open folder

Although the xdg-open manpage does not mention how to open a folder, calling xdg-open /bin works for me on my Ubuntu 14 VM, on my Xubuntu 14 VM and on WSL (Ubuntu 16) with LXDE installed.

It is also suggested on stackexchange; second reference

Therefore, I think a directory should not be a special case if UseShellExecute is set.

@danmosemsft thanks for your comment, I updated the description for this issue accordingly, pointing to the tests in corefx that illustrate the latest behavior

After thinking about it, I believe xdg-open does officially support to open directories. The man page says xdg-open opens a file or URL in the user's preferred application. For unixoid operating systems, directories are just "special files". From Wikipedia: The most common special file is the directory.

The manpage of xdg-open does not mention anything about only supporting regular files or forbidding special files or directories, so I think opening directories via xdg-open should be fine.

I set the label up-for-grabs to this issue.
@TSlivede in case you would like to throw a PR for this go ahead and let us know so that we assign it to you :)

PR dotnet/corefx#24017 fixes this issue.

So with the referenced code it's possible to open a folder x-platform?

@realvictorprm should be, try it out?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bencz picture bencz  路  3Comments

btecu picture btecu  路  3Comments

jchannon picture jchannon  路  3Comments

EgorBo picture EgorBo  路  3Comments

Timovzl picture Timovzl  路  3Comments