Batch file 在批处理文件中使用echo在单行中合并输出
我想修改下面的脚本,给我一个类似的输出Batch file 在批处理文件中使用echo在单行中合并输出,batch-file,echo,Batch File,Echo,我想修改下面的脚本,给我一个类似的输出 Number of processes on machine1 are 1 Number of processes on machine2 are 3 Number of processes on machine3 are 7 Number of processes on machine4 are 2 有人能帮忙吗 =============================== @echo off setlocal enabledelayedexp
Number of processes on machine1 are 1
Number of processes on machine2 are 3
Number of processes on machine3 are 7
Number of processes on machine4 are 2
有人能帮忙吗
===============================
@echo off
setlocal enabledelayedexpansion
pushd "%~dp0"
echo %date% %time%
TASKLIST /S machine1 | grep -c "process"
TASKLIST /S machine2 | grep -c "process"
TASKLIST /S machine3 | grep -c "process"
TASKLIST /S machine4 | grep -c "process"
=====================================您可以使用filter if IMAGENAME命令为您提供必要的处理。
@echo off
setlocal enabledelayedexpansion
pushd "%~dp0"
echo %date% %time%
TASKLIST /S machine1 | grep -c "process"
TASKLIST /S machine2 | grep -c "process"
TASKLIST /S machine3 | grep -c "process"
TASKLIST /S machine4 | grep -c "process"
我使用for命令是因为IMAGENAME的输出行为奇怪…它总是显示在行的开头
@echo off
set compName1=machine1
for /f %%a in ('tasklist /NH /FO CSV /FI "IMAGENAME eq process" ^| find /C /V ""') do (
echo Number of processes on %compName1% are %%a
)
你在windows下有grep吗?请编辑你的代码以确保可读性。例如,将任何代码缩进四个空格。然后,它以灰色突出显示。