Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Found spaces in my output inside created file ....why?  (Read 8633 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Found spaces in my output inside created file ....why?
« on: January 30, 2021, 07:17:36 PM »
hi all I have a batch to create an output text file containing all serial number of all workstations  With the help of an external file that contains the names of the hosts
but after I run it found that the output file has two kinds of situations
the first situation is my static output which contains the file information and written in normal form
the second situation is my dynamic output which contains the information I needed (the serials ) but it is written with spaces between each letter and looks like so strange form
Any help to fix this issue, please

Attached my code
Code: [Select]
@echo off
title Super Restart Batch using "External Text File"
setlocal enableextensions enabledelayedexpansion
color 0a
Rem mode 120,35
mode con:cols=90 lines=30
TIMEOUT /T 1 /NOBREAK >nul
ECHO.
ECHO.            *******************************************************************
ECHO.                                                                         
ECHO.                        Welcome to Amin Muhammad Batches                 
ECHO.                                                                         
ECHO.             This Batch to Get the Serial Number of all hosts located inside           
ECHO.               ( hosts.txt ) file which located in the same directory   
ECHO.                                                                         
ECHO.            *******************************************************************
ECHO.
TIMEOUT /T 1 /NOBREAK >nul

echo.  You are about to Get the whole machines serial number in your file, Are you sure?
TIMEOUT /T 1 /NOBREAK >nul
echo.
echo.  You have 30 Second to choose Or the program will terminate
choice /c YN /t 30 /d n /m  "    Click 'Y' to Continue or click 'N' to Cancel "

If %ErrorLevel%==1 GoTo y
If %ErrorLevel%==2 GoTo n

:y
cls
TIMEOUT /T 1 /NOBREAK >nul
echo This Operation has been Confirmed.
TIMEOUT /T 1 /NOBREAK >nul
echo Now it will start after the below timeout.
TIMEOUT /T 5 /NOBREAK
cls


set Online="Online Workstations Result.txt"
set Offline="Offline Workstations Result.txt"
set /a "countOn=0"
set /a "countOff=0"
set /a "rand=0"

echo.Welcome Everyone, >%Online%
echo.Welcome Everyone, >%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.Serial Number Report File for online workstations >>%Online%
echo.Serial Number Report File for offline workstations >>%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.This Process Started at %date% , %time% >>%Online%
echo.This Process Started at %date% , %time% >>%Offline%
echo.>>%Online%
echo.>>%Offline%
echo.[  HostName  :  Status                                       >>%Online%
echo.[  HostName  :  Status                ]>>%Offline%
echo.[            :                                               >>%Online%
echo.[            :                        ]>>%Offline%


for /f %%i in (hosts.txt) do (
   SET bHOSTUP=0
   ping -n 1 %%i -w 2000 |find "TTL=" > NUL && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      set g=%%i
      CALL :HOSTUP %%i
   ) else (
      set g=%%i
      CALL :HOSTDOWN %%i
   )
)

echo.>>%Online%
echo.>>%Offline%
echo.Total Online Machines is: %countOn% >>%Online%
echo.Total Offline Machines is: %countOff% >>%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.This Process Ended at %date% , %time% >>%Online%
echo.This Process Ended at %date% , %time% >>%Offline%
GOTO EOF

:n
cls
color fc
TIMEOUT /T 1 /NOBREAK >nul
echo.  This Operation has been canceled
TIMEOUT /T 3 /NOBREAK
GOTO EOF

:HOSTUP

Rem add 1 number to countOn variable for each online machine
set /a "countOn+=1"

Rem: get the serial number
wmic /node:%g% path win32_bios get serialnumber /format:csv

Rem: get the serial number and store it into text file
wmic /node:%g% path win32_bios get serialnumber /format:csv>>%Online%

set /a "rand+=5"
if %rand% geq 181 set /a "rand=0"
echo.[%g% : is Online and we got  the serial successfully>>%Online%


GOTO EOF

:HOSTDOWN

Rem add 1 number to countOff variable for each offline machine
set /a "countOff+=1"

Echo %g% : is Offline or Not Exist
echo.[%g% : is Offline or Not Exist]>>%Offline%
GOTO EOF

:EOF
exit /B

Example for hosts.txt content
host1
host2
host3
.........etc

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Found spaces in my output inside created file ....why?
« Reply #1 on: March 26, 2021, 01:11:19 PM »
All WMIC output is UNICODE.
Pipe the output to the MORE command and it will change it to ASNI
Code: [Select]
wmic /node:%g% path win32_bios get serialnumber /format:csv|MORE>>%Online%