如何将变量名和值从jython传递给batch fi

2024-04-20 08:37:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把变量名和值从jython脚本传递到批处理文件。另外,如何在批处理文件中访问它。你知道吗

在我的例子中,我想把变量名和值“bootstrapport”和“defaulthostport”传递给一个批处理文件部署.bat. 你知道吗

端口.jy

- 

      servers = AdminConfig.list( 'ServerEntry' ).splitlines() for server
        in servers : print '\n' print "Server Name : " +
       server[0:server.find('(')] print "=" *30 NamedEndPoints =
        AdminConfig.list( "NamedEndPoint" , server).splitlines() 
      for namedEndPoint in NamedEndPoints: endPointName =
       AdminConfig.showAttribute(namedEndPoint, "endPointName" ) 
    if endPointName == "BOOTSTRAP_ADDRESS": 
    bootstrapendPoint = AdminConfig.showAttribute(namedEndPoint, "endPoint" ) 
    host = AdminConfig.showAttribute(bootstrapendPoint, "host" ) 
    bootstrapport = AdminConfig.showAttribute(bootstrapendPoint, "port" ) 
    print "Endpoint Name : " + endPointName + " Host : " + host + " port : " +
               bootstrapport

     elif endPointName == "WC_defaulthost":
    defaulthostendPoint = AdminConfig.showAttribute(namedEndPoint,"endPoint" ) 
    host = AdminConfig.showAttribute(defaulthostendPoint,"host" )
     defaulthostport =AdminConfig.showAttribute(defaulthostendPoint, "port" ) 
    print "Endpoint Name : " + endPointName + " Host : " + host + " port : " +
               defaulthostport

        ========================================================================

Tags: 文件namehostserverportprintserversadminconfig
1条回答
网友
1楼 · 发布于 2024-04-20 08:37:18

解决了这个问题

将jython结果打印到文本文件中,然后将变量值从文本文件读取到批处理文件,然后删除文本文件。你知道吗

批处理文件

for /f "delims=" %%x in (Output) do set EMULATOR_PORT=%%x
echo EMULATOR_PORT %EMULATOR_PORT%
set "BOOTSTRAP_PORT="
for /f "skip=5 delims=" %%a in (Output) do if not defined BOOTSTRAP_PORT set BOOTSTRAP_PORT=%%a
del Output

相关问题 更多 >