У меня есть небольшой скрипт, который пытается выполнить внешнюю команду. Но по какой-то причине функция, которую я сделал для выполнения команды, полностью пропущена! Кажется, что ошибки не возникают, а просто не выполняются. У меня есть несколько отладочных операторов печати внутри, чтобы проверить, что функция введена, но они никогда не печатаются. И у меня есть инструкция печати за ее пределами, чтобы убедиться, что сценарий не умирает. Так что же дает?Почему моя функция python пропущена?
from xml.etree import ElementTree as et
import subprocess
pomFileLocation = "pom.xml"
uiAutomationCommand = "mvn clean install"
revertPomFileCommand = "git checkout pom.xml"
profileToSetToDefault = "smoketest"
def modifyxml(datafile, value):
print("modifying " + datafile)
tree = et.parse(datafile)
rootNodes = tree.getroot()
for node in rootNodes:
if "profiles" in node.tag:
for profile in node.iter():
foundIt = False
for param in profile.iter():
if "id" in param.tag and profileToSetToDefault in param.text:
foundIt = True
break
if foundIt == True:
for param in profile.iter():
if "activation" in param.tag:
for child in param.iter():
if "activeByDefault" in child.tag:
child.text = value
tree.write(datafile)
return
def runExternalCommand(comm):
print("running command " + comm)
p = subprocess.Popen(comm, bufsize=-1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
print(str(p))
while(True):
print("still running")
retcode = p.poll()
line = p.stdout.readline()
yield line
if(retcode is not None):
print("Exiting")
break
return
if __name__ == '__main__':
modifyxml(pomFileLocation, "true")
#runExternalCommand(uiAutomationCommand)
runExternalCommand(revertPomFileCommand)
print("finished")
где вы получаете определение 'runExternalCommand()'? Это сломано. Пожалуйста, оставьте комментарий, где вы его получите, чтобы другие не использовали сломанный код. [мой ответ содержит некоторые альтернативы] (http://stackoverflow.com/a/28352727/4279) – jfs