python输出中的powershell命令给出整数。为什么?

python输出中的powershell命令给出整数。为什么?,python,powershell,integer,Python,Powershell,Integer,上面的代码给出了错误输出: 回溯(最近一次呼叫最后一次): 文件“c:/Users/Administrator/Documents/IIS code/testing123.py”,第119行,在 对于policyINAppconfigFile.split()中的word: builtins.AttributeError:“int”对象没有属性“split”当您通过操作系统运行命令时,您会得到退出代码;不是返回值。子流程模块非常适合获取命令的输出: 导入子流程 导入操作系统 power\u s

上面的代码给出了错误输出:

回溯(最近一次呼叫最后一次): 文件“c:/Users/Administrator/Documents/IIS code/testing123.py”,第119行,在 对于policyINAppconfigFile.split()中的word:
builtins.AttributeError:“int”对象没有属性“split”

当您通过操作系统运行命令时,您会得到退出代码;不是返回值。子流程模块非常适合获取命令的输出:


导入子流程
导入操作系统
power\u shell=os.path.join(
操作系统环境[“系统根”],“系统32”,
“WindowsPowerShell”、“v1.0”、“powershell.exe”
)
policyINAppconfigFile=subprocess.check\u输出(
[power_shell,“-Command”,“findstr maxAllowedContentLength”,
“C:\\Windows\\sysnative\\inetsrv\\config\\applicationHost.config”]
)

policyINAppconfigFile是整数。你不能把它分开。也许您想将其拆分为字符串值?当我尝试这样拆分时:policyINAppconfigFile=str(policyINAppconfigFile)policyINAppconfigFile=policyINAppconfigFile.split()打印(policyINAppconfigFile)它返回['0',],我不知道为什么@YoskutikPolicyInAppConfigFile应该是什么?代码的目的是什么?我正在基于CIS基准测试执行Windows IIS策略,并尝试使用powershell命令从applicationHost.config文件中提取maxAllowedContentLength策略,该文件在powershell中提供输出。之后,我尝试使用powershell命令输出提取值40000000,以对照审计员输入进行检查@Yoskutik40000000是一个数字。你需要分成['4'、'0'、…、'0']吗?哦,这很有帮助!我现在将试着用我的代码和你给出的代码进行反复试验。谢谢大家!@Javier如果以上是答案,请注明!
import os
policyINAppconfigFile = os.system('%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command  "findstr "maxAllowedContentLength" C:\\Windows\\sysnative\\inetsrv\\config\\applicationHost.config "')
numbers = []
for word in policyINAppconfigFile.split():
    if word.isdigit():
        numbers.append(int(word))
print(numbers)