简体   繁体   English

拒绝访问Process.Start

[英]Access denied Process.Start

I get the error message "permission denied" when I run this code. 运行此代码时,出现错误消息“权限被拒绝”。 Is this error caused by the permissions on my mac or is it because of the code? 此错误是由我的Mac上的权限引起的还是由于代码引起的? I used the same example as MSDN. 我使用了与MSDN相同的示例。

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

Process.Start accepts the name of an executable or a document. Process.Start接受可执行文件或文档的名称。 According to the 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. 例如,如果您将文本文件与编辑器(如记事本)相关联,则文件名可以具有.txt扩展名;如果您将.doc文件与诸如Word的文字处理工具相关联,则文件名可以具有.doc。

This description may be limited to the Windows platform. 此描述可能仅限于Windows平台。 I would guess that the implementation on macOS is limited to running executable files. 我猜想在macOS上的实现仅限于运行可执行文件。

If you want to use MacOS's default editor then you should be able to run it as follows: 如果要使用MacOS的默认编辑器,则应该能够如下运行它:

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

Bear in mind that open is a MacOS-specific utility, so this won't work on other operating systems. 请记住, open是MacOS特定的实用程序,因此在其他操作系统上将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM