<!--
{
  "availability" : [
    "macOS: 10.8.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSUserUnixTask/execute(withArguments:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUserUnixTask(im)executeWithArguments:completionHandler:"
  },
  "title" : "execute(withArguments:completionHandler:)"
}
-->

# execute(withArguments:completionHandler:)

Execute the unix script with the specified arguments.

```
func execute(withArguments arguments: [String]?, completionHandler handler: NSUserUnixTask.CompletionHandler? = nil)
```

## Parameters

`arguments`

An array of `NSString` objects containing the script arguments. The arguments do not undergo shell expansion, so you do not need to do special quoting, and shell variables are not resolved.

`handler`

The completion handler Block that returns the result. See [`NSUserUnixTask.CompletionHandler`](/documentation/Foundation/NSUserUnixTask/CompletionHandler).

## Discussion

This method should be invoked no more than once for a given instance of the class.

If the script completed normally, the completion handler’s `error` parameter will be `nil`.

## See Also

[`standardOutput`](/documentation/Foundation/NSUserUnixTask/standardOutput)

The standard output stream.

[`standardError`](/documentation/Foundation/NSUserUnixTask/standardError)

The standard error stream.

[`init(url:)`](/documentation/Foundation/NSUserScriptTask/init(url:)-2qgls)

Return a user script task instance given a URL for a script file.

[`standardInput`](/documentation/Foundation/NSUserUnixTask/standardInput)

The standard input stream.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)