简体   繁体   中英

How to execute more than one commands by Process in Swift MacOS

I want to do the following actions: 1.change directory in to /Applications 2.open any app for example: open QQ.app

I successfully execute the following commands in CML: 1.cd /Applications 2.open QQ.app

I tried the following code but it doesn't work:

let process = Process()
process.launchPath = "/bin/bash"
process.arguments = ["cd /Applications"]
process.launch()

let process2 = Process()
process2.launchPath = "/bin/bash"
process2.arguments = ["open QQ.app"]
process2.launch()

Try adding;

 process.waitUntilExit()

before

 process2.launch()

Alternately you can add a termination handler on process and call process2 when the first handler runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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