4

I am looking for a way to set environment while using xcrun. We could set environment via xcrun simctl setenv prior to Xcode 7.0. Now we can only view environment using xcrun simctl getenv <device> <variable name>.

I have seen a reference of SIMCTL_CHILD_, but I am not sure how to use it.

xcrun simctl spawn
Usage: simctl spawn [-w | --wait-for-debugger] [-a <arch> | --arch=<arch>] <device> <path to executable> [<argv 1> <argv 2> ... <argv n>]
If you want to set environment variables in the resulting environment, set them in the calling environment with a SIMCTL_CHILD_ prefix.

I know that its a simple thing, and I am missing a tiny piece here.

Really appreciate if someone can help me with this.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
RKS
  • 1,333
  • 2
  • 12
  • 12
  • Does [this](http://stackoverflow.com/questions/27598931/launching-unit-tests-from-ios-sim-doesnt-execute-all-tests) help? – trojanfoe Jan 05 '16 at 18:22
  • Thank you for the pointer. I tried that already but its not setting up the environment correctly. I am trying it something like `SIMCTL_CHILD_DYLD_INSERT_LIBRARIES ="" ; SIMCTL_CHILD_XCInjectBundleInto ="" ; … ; xcrun simctl launch …`. But its not working. Am I doing something wrong here? – RKS Jan 05 '16 at 18:33
  • `export SIMCTL_CHILD_DYLD_INSERT_LIBRARIES ="" ; export SIMCTL_CHILD_XCInjectBundleInto ="" ; … ; xcrun simctl launch …` seems to communicate these environments variables to my simulators. – RKS Jan 05 '16 at 21:52
  • There has never been a 'setenv' subcommand of simctl. Please explain where you expect this environment variable to actually be set. The SIMCTL_CHILD_ environment variables effect the environments of the spawned processes, launched jobs, and boot environments. It's not really clear what a 'setenv' command would do or even how it would work. – Jeremy Huddleston Sequoia Jan 05 '16 at 23:44
  • [This](http://stackoverflow.com/questions/33633882/run-xctest-bundle-with-simctl) gives a better understanding of what I was trying to achieve. So the part to be able to set environment is resolved. – RKS Jan 05 '16 at 23:57

1 Answers1

6

In your shell script you can add a line like this:

export SIMCTL_CHILD_YOUR_ENVIRONMENT_VARIABLE_HERE=1

replacing YOUR_ENVIRONMENT_VARIABLE_HERE with the name of your environment variable.

Nick
  • 138,499
  • 22
  • 57
  • 95
Cortis Clark
  • 169
  • 1
  • 5