我有一个小脚本试图执行一个外部命令。但是由于某些原因,我用来执行命令的函数被完全跳过了!似乎没有出现错误,只是无法执行。我在里面有一些调试print语句来验证函数是否被输入,但是它们从不打印。我在它外面有一个print语句来验证脚本没有死。那么什么给予?在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" )

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐