为啥我的 Swift Process() 启动路径会吐出“启动路径不可访问”?

Posted

技术标签:

【中文标题】为啥我的 Swift Process() 启动路径会吐出“启动路径不可访问”?【英文标题】:Why is my Swift Process() launch path spitting out `launch path not accessible`?为什么我的 Swift Process() 启动路径会吐出“启动路径不可访问”? 【发布时间】:2019-09-17 01:08:45 【问题描述】:
            Button(action: 
                let installNano = Process()
                installNano.launchPath = "/opt/pkg/bin/pkgin"
                installNano.launch()
            ) 
            Text("Run pkgin")
            

我正在尝试这样做,因此当按下此按钮时,它将启动 pkgin 二进制文件,并且当运行登录二进制文件时,它应该显示此帮助页面:

Usage: pkgin [-cdfFhlnPtvVy] command [package ...]

Commands and shortcuts:
list                (ls  ) - List installed local packages
avail               (av  ) - List all available remote packages
search              (se  ) - Search for a remote package
install             (in  ) - Install or upgrade packages
update              (up  ) - Refresh local and remote package lists
upgrade             (ug  ) - Upgrade only packages marked with the keep flag
full-upgrade        (fug ) - Upgrade all packages
remove              (rm  ) - Remove packages and any dependent packages
keep                (ke  ) - Mark packages that should be kept
unkeep              (uk  ) - Mark packages that can be autoremoved
export              (ex  ) - Display PKGPATH for all keep packages
import              (im  ) - Import keep package list from file
show-keep           (sk  ) - Display keep packages
show-no-keep        (snk ) - Display autoremovable packages
autoremove          (ar  ) - Remove orphaned dependencies
clean               (cl  ) - Remove downloaded package files
show-deps           (sd  ) - List remote package direct dependencies
show-full-deps      (sfd ) - List remote package full dependencies
show-rev-deps       (srd ) - List local package reverse dependencies
provides            (prov) - Show which shared libraries a package provides
requires            (req ) - Show which shared libraries a package requires
show-category       (sc  ) - List all packages belonging to a category
show-pkg-category   (spc ) - Show categories a package belongs to
show-all-categories (sac ) - List all known categories
pkg-content         (pc  ) - Show remote package content
pkg-descr           (pd  ) - Show remote package long-description
pkg-build-defs      (pbd ) - Show remote package build definitions
stats               (st  ) - Show local and remote package statistics

但它反而在 Xcode 的 All Output 窗格中吐出这个错误:

2019-09-16 18:00:56.152377-0700 Jupiter[7507:210600] [General] launch path not accessible
2019-09-16 18:00:56.156127-0700 Jupiter[7507:210600] [General] (
    0   CoreFoundation                      0x00007fff2eb49a43 __exceptionPreprocess + 250
    1   libobjc.A.dylib                     0x00007fff64daf8f3 objc_exception_throw + 48
    2   Foundation                          0x00007fff3122d681 -[NSConcreteTask launchWithDictionary:error:] + 5234
    3   Jupiter                             0x0000000100001dcd $s7Jupiter11ContentViewV4bodyQrvg7SwiftUI05TupleC0VyAE6ButtonVyAE4TextVG_ALtGyXEfU_yycfU_ + 141
    4   SwiftUI                             0x00007fff3bc2fd09 $s7SwiftUI33PrimitiveButtonStyleConfigurationV7triggeryyF + 25
    5   SwiftUI                             0x00007fff3c07f510 $s7SwiftUI33PrimitiveButtonStyleConfigurationV7triggeryyFTA + 16
    6   SwiftUI                             0x00007fff3c07eeb9 $s7SwiftUI11Coordinator33_9FEBA96B0BC70E1682E82D239F242E73LLC14didPressButtonyySo8NSButtonCF + 25
    7   SwiftUI                             0x00007fff3c07eef6 $s7SwiftUI11Coordinator33_9FEBA96B0BC70E1682E82D239F242E73LLC14didPressButtonyySo8NSButtonCFTo + 38
    8   AppKit                              0x00007fff2bf74434 -[NSApplication(NSResponder) sendAction:to:from:] + 299
    9   AppKit                              0x00007fff2bfd3a30 -[NSControl sendAction:to:] + 86
    10  AppKit                              0x00007fff2bfd3962 __26-[NSCell _sendActionFrom:]_block_invoke + 136
    11  AppKit                              0x00007fff2bfd3864 -[NSCell _sendActionFrom:] + 171
    12  AppKit                              0x00007fff2bffbb17 -[NSButtonCell _sendActionFrom:] + 96
    13  AppKit                              0x00007fff2c3652a4 NSControlTrackMouse + 1745
    14  AppKit                              0x00007fff2bfd227c -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 130
    15  AppKit                              0x00007fff2bffb880 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 691
    16  AppKit                              0x00007fff2bfd1512 -[NSControl mouseDown:] + 748
    17  AppKit                              0x00007fff2bec4049 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4907
    18  AppKit                              0x00007fff2be075d8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2612
    19  AppKit                              0x00007fff2be06961 -[NSWindow(NSEventRouting) sendEvent:] + 349
    20  AppKit                              0x00007fff2bcc9b64 -[NSApplication(NSEvent) sendEvent:] + 352
    21  AppKit                              0x00007fff2bcb93c6 -[NSApplication run] + 707
    22  AppKit                              0x00007fff2bcab1c6 NSApplicationMain + 777
    23  Jupiter                             0x0000000100005bfd main + 13
    24  libdyld.dylib                       0x00007fff661022a5 start + 1
    25  ???                                 0x0000000000000003 0x0 + 3
)

我不明白为什么它会给我launch path not accessible 错误,因为我已经检查了我多次使用的启动路径,并且路径和所有内容都在我的计算机上,所以它没有任何意义我为什么这不起作用。当使用Command + Shift + G 并输入启动路径时,它会将我带入文件夹并选择pkgin,所以一切都肯定是100%,这让我感到困惑,因为如果一切都在那里,那么路径应该可以工作。如果您对为什么这不起作用有任何想法,任何帮助。

【问题讨论】:

我怀疑这与应用沙盒、安全措施有关。我知道 Catalina 添加了一系列新的安全措施,请查看这些。 @Alexander 沙盒权利设置为是,我想我可以尝试更改它。 @Alexander 是的,沙盒就是问题所在!发布您所说的作为答案,以便我将其标记为解决方案。 你应该准确地写下你所做的作为答案,并接受你自己的答案。我并没有真正做太多。 【参考方案1】:

我只需要转到我的应用程序的权利并将沙盒从“是”设置为“否”即可解决问题。

【讨论】:

以上是关于为啥我的 Swift Process() 启动路径会吐出“启动路径不可访问”?的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的 FinderSync 扩展在启动之前就崩溃了?

为啥不在swift 3中将database.db从bundle复制到文档目录? [复制]

为啥viewDidLoad在swift中完成时不显示数据? [关闭]

process.start启动exe,程序中会调用配置文件的路径是相对路径,产生启动错误,怎么办?

WPF 利用Process.Start()方法启动指定路径下的exe文件并传递参数接收参数

C# Process.Start 路径