I am trying to spawn a subprocess that invokes a command with a json parameter that I get from a file. However, the json parameter used by the subprocess seems to produce an error because the json has a u prefix to indicate it is unicode.
I am not sure how I can get around this as I thought I had already converted the json to a string when I form the command
import sys
import json
from subprocess import Popen, PIPE
json_file = sys.argv[1]
# Read the provided policy file
with open(json_file, 'r') as f:
values= json.load(f)
for value in values:
command = ('''value definition create --name {} --rules '{}'
''').format(value['name'], value['definition'])
p = Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
print(stdout)
print(stderr)
The std error is outputting the following:
error: unrecognized arguments: values uif: {ufield: utype, ...
Here is the json file:
[
{
"name":"testValue",
"definition":{
"if":{
"field":"type",
"in":[
"TestValue"
]
},
"then":{
"effect":"Deny"
}
}
}
]