I have a Python script where I run SFDX commands using subprocess module, here is part of my code:
query = run(f'sfdx force:data:soql:query -u myOrg -q "SELECT Id FROM CronTrigger"', shell=True, universal_newlines=True, stdout=PIPE, stderr=STDOUT).stdout
Here is how I validate an update:
update = run(f'sfdx force:data:record:update -u MyOrg -s User -w Emailfirstname.lastname@example.org' -v Emailemail@example.com', shell=True, universal_newlines=True, stdout=PIPE, stderr=STDOUT).stdout
if 'Succesfully' in update:
The thing is, the only way I can work with the result of any SFDX command is to read the output of stdout, which is a string, and then I have to parse it to find the substring that I need.
Also, to validate the success or failure of an Update, I find a 'Successfully' substring within the output. Is there a way I can get a return code from Salesforce, or perhaps an output in json format or dictionary type so I can refer to the records and values instead of reading the output?