从在Windows批处理脚本文件读取值 [英] Reading a value from a file in a windows batch script

查看:791
本文介绍了从在Windows批处理脚本文件读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从文件中读取一个值,并在随后的命令中使用它。

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

我有一个叫(或只是数字,它不是一个属性文件类的东西)文件 AppServer.pid ,其中包含我的应用程序服务器的进程ID。

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).

应用服务器挂了,所以我想利用这个值,并把它传递给kill命令。所以,我的脚本将会像

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

有没有一种便捷的方式在Windows脚本来做到这一点?

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

推荐答案

这个作品:

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

与使用SET / p参数允许您使用用户输入设置参数的值(或在这种情况下,从文件输入)

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)

这篇关于从在Windows批处理脚本文件读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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