brigadir brigadir - 7 months ago 13
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

setup()
and
tearDown()
methods of test cases. The purpose is to launch screen recording while the test is running.

Answer

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: http://joelinoff.com/blog/?p=1658 we can write simple web-server to handle POST request and performs some action.

In my case the action is to call bash script

os.system(someCommandString)

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("http://0.0.0.0:8080/command", parameters: params, success: { (NSURLSessionDataTask, AnyObject) in
        print("succeed")
    }, failure: { (NSURLSessionDataTask, NSError) in
        print("failed")
    })
Comments