Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a value from a file in a windows batch script

I'm trying to read a value from a file and use it in a subsequent command.

I have a file called AppServer.pid which contains the process id of my app server (just the number, it's not a properties file or anything like that).

The app server is hanging, so I want to take this value and pass it to the kill command. So my script will be something like

SET VALUE_FROM_FILE=AppServer.pid # or something
taskkill /pid %VALUE_FROM_FILE% /f

Is there a convenient way to do this in Windows scripting?

like image 527
Harry Lime Avatar asked Nov 18 '08 09:11

Harry Lime


2 Answers

This works:

SET /P VALUE_FROM_FILE= < AppServer.pid
taskkill /pid %VALUE_FROM_FILE% /f

The /P parameter used with SET allows you to set the value of a parameter using input from the user (or in this case, input from a file)

like image 128
Cocowalla Avatar answered Oct 07 '22 17:10

Cocowalla


for /f %%G in (appid.txt) do (SET PID=%%G)
echo %PID%
taskkill etc here... 

This might help !

like image 31
RuntimeException Avatar answered Oct 07 '22 17:10

RuntimeException