在wlst控制台使用语句或循环时遇到错误

0 投票
1 回答
1202 浏览
提问于 2025-04-18 10:10

无法在循环后面添加语句。

举个例子:

wls:/ADMIN_server/serverConfig> serverRuntime()
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

wls:/ADMIN_server/serverRuntime> dsMBeans = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
wls:/ADMIN_server/serverRuntime> ds_name = "ADMIN_DB"
wls:/ADMIN_server/serverRuntime> for ds in dsMBeans:
...
Traceback (innermost last):
  (no code object) at line 0
  File "<console>", line 2
SyntaxError: invalid syntax

我不确定在使用这些选项之前是否需要导入什么东西,所以我无法在循环中添加语句:

import time
import sys

1 个回答

1

你不需要特别导入什么东西就可以使用WLST中的循环机制。例如,可以试试下面的代码:

slist=range(1,4)
for i in slist: print 'i = ' + str(i);

运行后应该会得到:

i = 1
i = 2
i = 3

在你的for循环后面的语句可能会导致你的python脚本出问题,或者如果你是手动输入命令的话,要确保在...后面加一个空格,这样才能让它正确理解下一行,比如:

wls:/offline> j = 0
wls:/offline> while j<4:
... print 'j = ' + str(j)
... j = j + 1
...
jms 0
jms 1
jms 2
jms 3

注意,在...后面输入一个空格是非常重要的,否则你会遇到无效语法的错误。

撰写回答