I'm looking at this script to disable shell=True while creating an ova.
It works when shell=True but gives me a TypeError when shell=False.
I'm pretty sure the issue is with this part of the command - " vi:\//" + username + ":" + encodedPassword + "@" + hostname"
- because when I remove this element from the list (i.e. command), the script moves forward.
I've tried hardcoding values like "vi:\//user:[email protected]"
and also removed so but I still get this type error.
Python version is 2.7
com1 = "/usr/bin/ovftool --acceptAllEulas --disableVerification --noSSLVerify --datastore=" + datastore +
" --network=\"" + network + "\" --name=" + name + " " + ovalocation + " vi:\//" + username +
":" + encodedPassword + "@" + hostname
#prior to disabling shell=True
# coms = subprocess.Popen(com1, shell=True,
# stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# set shell=False - now it requires the command to be a list rather than a string.
coms = subprocess.Popen(com1.split(), shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Error:
'unsupported operand type(s) for +: 'Popen' and 'str''
What am I doing wrong?
Edit:
I know it's an issue with the vi command becuase when replace "vi:\//" + username + ":" + encodedPassword + "@" + hostname"
with a hardcoded "hello"
the script moves forward.
If you are using a lot of argument's, it might be easier using a
string
instead of alist of arguments
which you can do by settingshell=True
. That's easy to debug as well, as the same command (which you should print) will run from a native shell in the same fashion.Just keep in mind, that
shell=True
might have security issues depending on how this is being run.