brigadir brigadir - 2 years ago 162
Bash Question

From iOS app on Simulator, launch OS X shell script

Is it possible from inside iOS app code to run Mac OS X shell script (or any other OS X program)?

The concrete situation is following: I'm playing with UI XCTests and want to run shell script in

methods of test cases. The purpose is to launch screen recording while the test is running.

Answer Source

Okay, looks like nobody knows easy workarounds. So I solved it with local web-server on python.

Python has built-in BaseHTTPServer class. With this tutorial for example: we can write simple web-server to handle POST request and performs some action.

In my case the action is to call bash script


To launch all this mechanism we need to run python webserver. Then inside XCTestCase subclass in setup() and tearDown() methods we perform request to the server, ex:

    AFHTTPSessionManager().POST("", parameters: params, success: { (NSURLSessionDataTask, AnyObject) in
    }, failure: { (NSURLSessionDataTask, NSError) in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download