我想从Jenkins调用一个Python脚本,让它构建我的应用程序,将其FTP到目标,然后运行它。在
我正在尝试构建,subprocess
命令失败。我用subprocess.call()
和subprocess.popen()
两种方法进行了尝试,结果是相同的。在
当我计算shellCommand
并从命令行运行它时,构建成功。在
请注意,我有3个shell命令:1)删除工作目录,2)创建一个新的、空的工作目录,然后3)构建。前两个命令从subprocess
返回,但第三个命令挂起(尽管从命令行运行时完成)。在
我做错什么了?或者,我有什么选择来执行这个命令?在
# +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
def ExcecuteShellCommandAndGetReturnCode(arguments, shellCommand):
try:
process = subprocess.call(shellCommand, shell=True, stdout=subprocess.PIPE)
#process.wait()
return process #.returncode
except keyboardInterrupt, e: # Ctrl-C
raise e
except SystemExit, e: # sys.exit()
raise e
except Exception, e:
print 'Exception while executing shell command : ' + shellCommand
print str(e)
traceback.print_exc()
os._exit(1)
# +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
def BuildApplciation(arguments):
# See http://gnuarmeclipse.github.io/advanced/headless-builds/
jenkinsWorkspaceDirectory = arguments.eclipseworkspace + '/jenkins'
shellCommand = 'rm -r ' + jenkinsWorkspaceDirectory
ExcecuteShellCommandAndGetReturnCode(arguments, shellCommand)
shellCommand = 'mkdir ' + jenkinsWorkspaceDirectory
if not ExcecuteShellCommandAndGetReturnCode(arguments, shellCommand) == 0:
print "Error making Jenkins work directory in Eclipse workspace : " + jenkinsWorkspaceDirectory
return False
application = 'org.eclipse.cdt.managedbuilder.core.headlessbuild'
shellCommand = 'eclipse -nosplash -application ' + application + ' -import ' + arguments.buildRoot + '/../Project/ -build myAppApp/TargetRelease -cleanBuild myAppApp/TargetRelease -data ' + jenkinsWorkspaceDirectory + ' -D DO_APPTEST'
if not ExcecuteShellCommandAndGetReturnCode(arguments, shellCommand) == 0:
print "Error in build"
return False
我在google上进一步搜索发现了this page,在1.2处显示
果然,当我从上面的代码中删除
, stdout=subprocess.PIPE
时,它就如预期的那样工作了。在由于我只需要子进程的退出代码,以上代码对我来说就足够了。如果需要命令的输出,请阅读链接页。在
相关问题 更多 >
编程相关推荐