访问被拒绝 Process.Start

Access denied Process.Start

当我 运行 此代码时,我收到错误消息 "permission denied"。这个错误是我的 mac 的权限导致的还是因为代码?我使用了与 MSDN 相同的示例。

static void Main(string[] args)
{
    Process.Start("readme.txt");
};

Process.Start 接受可执行文件或文档的名称。根据 docs:

The file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated.doc files with a word processing tool, such as Microsoft Word.

此描述可能仅限于 Windows 平台。我猜想在 macOS 上的实现仅限于 运行ning executable 个文件。

如果你想使用 MacOS 的默认编辑器,那么你应该可以 运行 如下:

Process.Start("open", "readme.txt")

请记住,open 是 MacOS 专用的实用程序,因此它不适用于其他操作系统。