Bit about the setup and goal first; I have Core installed and a session running that I wish to run a few commands on from a python script. Since there are only a few commands and they are fairly simple commands, figured I'd just use subprocess.Popen to kick of coresendmsg instead of trying to implement the core control plane in my script.
An example of the command (as run from the CLI) is as follows:
coresendmsg exec node=2 num=1001 cmd='ifconfig eth0 192.168.0.1'
I've had some issues with running this command from python and having coresendmsg properly parse the cmd argument. If run as seen below, coresendmsg considers eth0 and 192.168.0.1 as separate arguments and chokes, which makes sense to me.
s=subprocess.Popen(['coresendmsg',
'exec',
'-s 47854',
'node=2',
'num=1001',
'cmd=ifconfig eth0 192.168.0.1'])
If I then change it to the following, coresendmsg now considers the cmd as a single argument, but still chokes because the single quotes are now included when the arguments are split up in coresendmsg. This is different then when the coresendmsg is run from the commandline with the same quotes, as seen in the example above.
s=subprocess.Popen(['coresendmsg',
'exec',
'-s 47854',
'node=2',
'num=1001',
'cmd=\'ifconfig eth0 192.168.0.1\''])
I know this because I went in and modified coresendmsg to print the arguments and checked both cases. When the command above run from CLI, I see this:
['exec', 'node=2', 'num=1001', 'cmd=ifconfig eth0 192.168.0.1']
but when run from python I get one of the following depending on how i quote things:
['exec', 'node=2', 'num=1001', 'cmd=ifconfig', 'eth0', '192.168.0.1']
['exec', 'node=2', 'num=1001', "cmd='ifconfig eth0 192.168.0.1'"]
['exec', 'node=2', 'num=1001', 'cmd="ifconfig eth0 192.168.0.1"']
I can make this work from a bash script but I'd rather not run a script, from a script, from a script. Looking for any suggestions that might resolve this problem.
'-s 47854'. Try to change that to'-s', '47854'