Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear,
I have some problem about batch programming,
I have to write batch that find line
"Server (PID = 1856) Ready" or
"Server Mode 2 (PID = 2453) Ready"
in file and assign 1856 or 2453 to a variable.Note that a line can be at anywhere in file.
1 file has only 1 line.How can i do all of this with windows bat script? Or i need some execute program to help.
If anyone can help me it is a pleasure.Thank you very much.
Pednoy

Do you mean that the file that batch is looking at has only one line?
Everything is on the same line?
Post the file.
M2

Sorry for unclear information.
There are many files that generated from my system. Each file will contain many lines and will contain one of two lines I mentioned above.
Unfortunately that I can not know exactly where "Server (PID = 1856) Ready" or
"Server Mode 2 (PID = 2453) Ready" will be at which line number.Because the files are generate from legacy system and has variety name.
For detecting file name and read it, I can do now.
Next step is to retrieve number after "PID =" to assign to a variable.Is there anyway to do this?

Hi,
This should do it:
::##
@echo off
set MYVar=find "Server (PID = 1856) Ready" filename
if errorlevel 1 goto next
set MYVar=1856
goto end:next
find "Server Mode 2 (PID = 2453) Ready" filename
if errorlevel 1 goto end
set MYVar=2453:end
M2

Thanks Mechanix2Go.
You gave me many ideas.How about if it is possible to find "(PID =" and move cursor to after its position. then read number after that until find ")".Because number is process number and it can vary.
Thanks for you kindly help

pednoy,
This should do it:
@echo off
:: This is the world-famous PID setter bat by Computer Mechanix
:: http://www.Golden-Triangle.com
::set MYvar=
set MYvar2=
set PID=
set Mode2PID=find "Server Mode 2 (PID" <filename>mode2
find "Server (PID" <filename>NOmode2set /p MYvar2=<mode2
set /p MYvar=<NOmode2set PID=%MYvar:~15,4%
set Mode2PID=%MYvar2:~22,4%echo PID= %PID%
echo Mode2PID= %Mode2PID%
M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |