批处理命令从文本文件中提取变量 [英] Batch command to pull variables from a text file

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

问题描述

是否有用于批处理文件的命令以读取文本文件并将内容用作变量?不久前,我听说过一个命令,该命令可以读取文本文件的最后一行并将其分配为批处理文件中的变量,但我不记得该命令是什么,或者它是否有效.有这样的命令吗?我已经尝试过类似的事情:

Is there any command for a batch file to read a text file, and use the content as a variable? A while back I'd heard about a command that could read the last line of a text file and assign this as a variable in the batch file, but I can't remember what the command was or if it even worked. Is there such a command? I've tried things like:

Set /a var < directory.bat\file.txt

返回值为0的值,或

Set /p var < directory.bat\file.txt

Set /i var < directory.bat\file.txt

,它给出错误命令的语法不正确.我是在使用"set"命令在正确的轨道上,还是为此使用完全不同的命令(或者我将不得不编写一个完全不同的,多行脚本来执行此操作)?

, which gives the error "the syntax of a command is incorrect. Am I on the right track with "set" commands, or is there a completely different command for this (or will I have to write an entire different, multi-line script to do this)?

推荐答案

set/p var =< directory \ file.txt

将从文本文档中抓取第一行.

that will grab the first line out of a text document.

这篇关于批处理命令从文本文件中提取变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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