批处理脚本不显示任何输出 [英] Batch Script shows no output

查看:298
本文介绍了批处理脚本不显示任何输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考我以前的问题和收到的答复(可以在此处找到),我正在寻求有关批处理脚本的帮助.根据对上述问题的答复,我创建了一个批处理脚本,如下所示:

With reference to my previous question and responses received (which can be found here), I am seeking a help regarding a Batch Script. Based on the responses received to above mentioned question, I have created a Batch script which is as follows:

@echo off

setlocal enabledelayedexpansion

ping -n 1 %1 | find "TTL=" > NUL
IF NOT ERRORLEVEL 1 (

FOR /F %%i IN ('wmic /node:%1 computersystem get Name') DO (SET A=%%i)

FOR /F %%i IN ('wmic /node:%1 computersystem get Domain') DO (SET B=%%i)

FOR /F %%i IN ('wmic /node:%1 computersystem get UserName') DO (SET C=%%i)

FOR /F %%i IN ('wmic /node:%1 computersystem get Manufacturer') DO (SET D=%%i)

FOR /F "delims=" %%i IN ('wmic /node:%1 computersystem get Model') DO (SET E=%%i)
FOR %%a in (%E%) DO (SET E=%%a)

FOR /F %%i IN ('wmic /node:%1 computersystem get SystemType') DO (SET F=%%i)

FOR /F %%i IN ('wmic /node:%1 bios get SerialNumber') DO (SET G=%%i)

FOR /F "delims=|" %%i IN ('wmic /node:%1 os get Name') DO (SET H=%%i)
FOR %%a in (%H%) DO (SET H=%%a)

FOR /F %%i IN ('wmic /node:%1 os get TotalVisibleMemorySize') DO (SET J=%%i)

FOR /F "delims=" %%i IN ('wmic /node:%1 cpu get Name') DO (SET K=%%i)
FOR %%a in (%K%) DO (SET K=%%a)


echo !A!,!B!,!C!,!D!,!E!,!F!,!G!,!H!,!J!,!K! >> output.csv

)

问题在于,当使用有效参数执行上述脚本时,它既不显示任何错误消息,也不显示生成的CSV文件中的任何数据.我无法理解该脚本出了什么问题.

The problem is that, when above script is executed with a valid argument, it neither displays any error message not displays any data in the generated CSV file. I am not able to understand what is wrong with the script.

推荐答案

1-每次调用wmic都可以检索尽可能多的信息

1 - Retrieve as much information you can from each call to wmic

2-过滤wmic的输出.在这种情况下,我正在使用find搜索包含所指示节点的行.

2 - Filter the output of wmic. In this case, i'm using find to search the line containing the indicated node.

3-如果可能的话,为避免不得不删除行尾的附加CR,请检索一个不会读取的附加字段.

3 - If possible, to avoid having to remove the aditional CR at the end of the line, retrieve an aditional field that you will not read.

4-wmic的输出带有节点名和按字母顺序排序的字段的前缀.为此定义tokens记帐.

4 - Output from wmic is prefixed with the node name and fields ordered alphabetically. Define tokens accounting for this.

@echo off

    setlocal enableextensions disabledelayedexpansion

    set "node=%~1"

    ping -n 1 %node% | find "TTL=" > NUL
    if errorlevel 1 goto endProcess

    for /f "tokens=2-7 delims=," %%a in (
        'wmic /node:"%node%" computersystem get domain^,manufacturer^,model^,name^,systemtype^,username^,wakeuptype /format:csv ^| find /i "%node%"'
    ) do (
        set "_domain=%%a"
        set "_manufacturer=%%b"
        set "_model=%%c"
        set "_name=%%d"
        set "_systemType=%%e"
        set "_userName=%%f"
    )

    for /f "tokens=2 delims=," %%a in (
        'wmic /node:"%node%" bios get serialNumber^,version /format:csv ^| find /i "%node%"'
    ) do (
        set "_serialNumber=%%a"
    )

    for /f "tokens=2-3 delims=," %%a in (
        'wmic /node:"%node%" os get description^,totalvisiblememorysize^,version /format:csv ^| find /i "%node%"'
    ) do (
        set "_osName=%%a"
        set "_memory=%%b"
    )

    for /f "tokens=2 delims=," %%a in (
        'wmic /node:"%node%" cpu get name^,version /format:csv ^| find /i "%node%"'
    ) do (
        set "_cpu=%%a"
    )

    echo %_name%,%_domain%,%_userName%,%_manufacturer%,%_model%,%_systemType%,%_serialNumber%,%_osName%,%_memory%,%_cpu%

:endProcess
    endlocal

这篇关于批处理脚本不显示任何输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆