import subprocess

json = "C:\Users\Onion1\inputs.json"[json])

tried above methods but couldn't able to open and call in subprocess.

with open("C:\Users\O\ss.txt") as out: subprocess.Popen("ls",stdout=out)

1 Answers

shubham On Best Solutions

Read file as follows, btw this is not the only way to read file.

>>> filename = "inputs.json"
>>> fd = open("inputs.json")
>>> json_content =
>>> fd.close()
>>> print(json_content)
{"sender": "AB", "body": "Trade order wall movement quite with want large. Store whose magazine ability so interest artist. Owner federal west.\nIt situation take kid money structure. Throughout may whose much or training", "id2": "2119739392053", "id": "111", "device_id": "9878"}


Calling ls -l using subprocess

>>> import subprocess
>>>["ls", "-l"])
total 4
drwxrwxr-x 3 admin-pc admin-pc 4096 May  7 16:14 cJSON_Test
-rw-rw-r-- 1 admin-pc admin-pc    0 May 10 10:51 inputs.json

Since I am unaware of what you what process you want to execute using subprocess, so I used ls -l as an example. Also i'm not clear about whether you want to pass json file content to process or json filename.

Read more about subprocess here