'xcrun xctrace list devices' gives list of devices info in stderr - Python

'xcrun xctrace list devices' gives list of devices info in stderr when ran in subprocess. Can any one help me on this?
Answered by Developer Tools Engineer in 641666022
Hi Sivaji_SE,

That's unexpected. Can you please provide some steps to reproduce it? How are you running the xctrace tool?
Accepted Answer
Hi Sivaji_SE,

That's unexpected. Can you please provide some steps to reproduce it? How are you running the xctrace tool?
Same in java and common terminal execution, just redirect error stream to a file.

To reproduce in java, just create ProcessBuilder with proper command and start it.
To read stream I used:

Code Block
import org.apache.commons.io.IOUtils;
IOUtils.readLines(process.getInputStream(), encoding)

InputStream returns nothing, while all output is in error stream.


I had also problems with output encoding. On my local machine output was in UTF16LE encoding for some reason, while on other machines it was in UTF8
I was trying to get the information of all ios real devices (connected to my machine) and also the simulators.

import subprocess

def getdeviceinfo(self):
alldevicesinfo = subprocess.run(['xcrun', 'xctrace', 'list', 'devices'], stdout=subprocess.PIPE).stdout.decode(
'utf-8')

The above process gives me the o/p as an empty string but, gives the expected information in stderr (in the error)


Try the below code:
alldevicesinfo = subprocess.run(['xcrun', 'xctrace', 'list', 'devices'], stderr=subprocess.PIPE).stderr.decode(
'utf-8')
I had the same problem and solved it by redirecting stderr to stdout with xcrun xctrace list devices 2>&1

You could also use

import subprocess

completed_process = subprocess.run(['xcrun', 'xctrace', 'list', 'devices'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
all_devices_info = completed_process.stderr.decode('utf-8')
'xcrun xctrace list devices' gives list of devices info in stderr - Python
 
 
Q