gpt4 book ai didi

batch-file - 我的批处理脚本有 "Missing operator"

转载 作者:行者123 更新时间:2023-12-04 01:18:35 25 4
gpt4 key购买 nike

我正在尝试获取我的安装程序脚本的系统信息。这是我的简单批处理脚本。

@echo off
setlocal enableextensions enabledelayedexpansion

echo System information now loading...

for /f "delims=" %%l in ('wmic os get * /format:list') do >nul 2>&1 set "OS_%%l"
for /f "delims=" %%l in ('wmic cpu get * /format:list') do >nul 2>&1 set "CPU_%%l"
set /a FreeSpace=0
for /f "skip=1 tokens=1,2" %%A in ('wmic logicaldisk get FreeSpace') do (
if "%%B" neq "" for /f %%N in ('powershell !FreeSpace!+%%A') do (
set FreeSpace=%%N
)
)

echo wsh.echo cdbl(%FreeSpace%)/1024/1024/1024 > %temp%.\tmp.vbs
for /f %%a in ('cscript //nologo %temp%.\tmp.vbs') do set /a HDD_FreeSpace=%%a
del %temp%.\tmp.vbs

set /a RAM_Memory=%OS_TotalVisibleMemorySize%/1024
set /a CPU_Speed=%CPU_NumberOfLogicalProcessors%*%CPU_CurrentClockSpeed%

>>SystemInfo.log 2>&1 echo Operating System: %OS_Caption%%OS_OSArchitecture% (%OS_Version%, Build %OS_BuildNumber%)
>>SystemInfo.log 2>&1 echo Processor: %CPU_Name%
>>SystemInfo.log 2>&1 echo RAM: %RAM_Memory% MB
>>SystemInfo.log 2>&1 echo HDD Total Free Space: %HDD_FreeSpace% GB

>>SystemSource.log 2>&1 echo %OS_Version%
>>SystemSource.log 2>&1 echo %CPU_Speed%
>>SystemSource.log 2>&1 echo %OS_TotalVisibleMemorySize%
>>SystemSource.log 2>&1 echo %FreeSpace%

exit

输出SystemInfo.log

Operating System: Microsoft Windows 7 Professional 32-bit (6.1.7601, Build 7601)
Processor: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
RAM: 3069 MB
HDD Total Free Space: 61 GB

输出SystemSource.log

6.1.7601
4784
3143284
66427858944

一切似乎都很好。但是批处理脚本显示“缺少运算符(operator)”,我不知道为什么显示了一条消息,但所有输出都是正确的。

会不会崩溃?

最佳答案

去掉@echo off。您会看到 设置/a HDD_FreeSpace=375.6279296875 的行集。期间无效

c:\>for /F %a in ('cscript //nologo C:\Users\PREET~1.SAN\AppData\Local\Temp.\tmp.vbs') do set /a HDD_FreeSpace=%a

c:\>set /a HDD_FreeSpace=375.625617980957
Missing operator.

c:\>del C:\Users\PREET~1.SAN\AppData\Local\Temp.\tmp.vbs

试试用 *SET * 代替

关于batch-file - 我的批处理脚本有 "Missing operator",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com