简体   繁体   中英

python 3 How do I send multidimentional array data to a subprocess.call()

I have a shell command I need to send a multidimensional array as parameters.

subprocess.call(['rndc', 'addzone', domain, 'in', 'external', '"{type master; auto-dnssec maintain; inline-signing yes; key-directory \"/home/ex-mailer-domains/domain.com/\"; file \"/home/ex-mailer-domains/domain.com/domain.com.external\"; update-policy { grant ddns-key zonesub ANY; };};"'

subprocess.call(['rndc', 'loadkeys', domain])

the error I am receiving:

[\u@yoda:/usr/local/etc/namedb] # python3.4 makedomain3.py mylabel domain.com 108.61.169.203 255.255.254.0 2001:19f0:5800:8561:5400:00ff:fe07:cae5 1
  File "makecustdomain3.py", line 249
    subprocess.call(['rndc', 'loadkeys', domain])
             ^
SyntaxError: invalid syntax

actual command in the shell:

rndc addzone domain.com in external '{type master; auto-dnssec maintain; inline-signing yes; key-directory "/home/ex-mailer-domains/domain.com/"; file "/home/ex-mailer-domains/nyctelecomm2.com/domain.com.external"; update-policy { grant ddns-key zonesub ANY; };};'
rndc loadkeys domain.com

How do you correctly pass multidimensional array data as a parameter to a subprocess.call() in python3?

I believe that you failed to close off the previous call. The first call in your posting ends with "' ; these close off the structure string, but you still need a right bracket and right parenthesis.

The parser detects this at the end of the following token; syntactically, it should have seen either the right bracket or another comma.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM