2

Whenever I run the following code, a sound is played perfectly fine but it always prints something to the console. code:

let path = Bundle.main.bundlePath
let task = Process()
        
task.launchPath = "/usr/bin/env"
task.arguments  = ["afplay", path]
        
let _ = try? task.run()
        
task.waitUntilExit()

console message:

2023-05-07 01:18:05.779125+0200 afplay[7755:301446] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000020c1c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2023-05-07 01:18:05.799089+0200 afplay[7755:301446] [aqme]        MEMixerChannel.cpp:1636  client <AudioQueueObject@0x10100f200; [0]; play> got error 2003332927 while sending format information
2023-05-07 01:18:06.554636+0200 afplay[7755:301448] [aqme]        MEMixerChannel.cpp:1636  client <AudioQueueObject@0x10100f200; [0]; play> got error 2003332927 while sending format information
You are in First Layer spawn

I've tried clearing the terminal by running a different process with launchPath /usr/bin/clear but it still doesn't work

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
meep
  • 23
  • 1
  • 6
  • I think this problem might be related to [this one](https://stackoverflow.com/questions/58360765/swift-5-1-error-plugin-addinstanceforfactory-no-factory-registered-for-id-c?noredirect=1&lq=1). – McKinley May 06 '23 at 23:34

1 Answers1

0

Setting task.standardOutput and task.standardError to nil before calling task.run(), I think will cause anything the subprocess outputs to stdout and stderr to be ignored.

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45