How can I run Instruments from Python?
Question: Anyone know how to run Instruments from Python? I tired to use os.system and
it didn't work.

If I run Instruments from a command line, I only need to run:

    
    
    instruments -w id -t xxxxxxxxxxxxxx xx.js
    

I will need to run the above in python. I suppose the following will work

    
    
    import os
    os.system('instruments -w id -t xxxxx xx.js')
    

I also tried with os.system ('open -a instruments xxxxxx')

Neither way worked. Anyone have a better idea?

I expected it to run instruments just like running it from command line. And
start to run javascritps using instruments. It didn't happen. What happened
was just a 256 printed out.


Answer: It's hard to tell from your code snippet because you might have cut a lot out
to be brief, but it looks like you are invoking the command for instruments
incorrectly. Here's a line-broken example:

    
    
    instruments \
      -D [trace document to write] \
      -t [Automation Trace Template] \
      [Your App Bundle] \
      -e UIARESULTSPATH [where results should be written] \
      -e UIASCRIPT [your actual script file
    

For a full example of how to run Instruments from the command line, check out
my [demo
repo](https://github.com/jonathanpenn/AutomationExample/blob/master/run_automation.sh).

That has a shell script that walks through how it works to invoke Instruments
from the command line. You can use that as the basis for launching from
Python.

Also, I include a copy of my `unix_instruments` wrapper script. Instruments
doesn't return a non-zero status code if automation scripts log failures, so
this wrapper script keeps an eye on all the log output and returns a non-zero
status code for you. How to use it is all in the repo, too.

