windows ASSIGN win XP 命令行输出到变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/537404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASSIGN win XP commandline output to variable
提问by
i would like to translate a following script from linux shell to Windows XP shell
我想将以下脚本从 linux shell 转换为 Windows XP shell
GPSID=$(awk '/GPSID/ {print }' gora.RTK )
awk -v variable=${GPSID} 'BEGIN {printf "Numer seryjny : " variable,}' >>out.txt
The second line has been translated; the problem is with defining a variable that contains shell output in windows :-(
第二行已翻译;问题在于在 Windows 中定义一个包含 shell 输出的变量:-(
回答by
ok problem fixed
好的问题解决了
for /f "tokens=*" %%a in ('awk "/GPSID/ {print }" gora.RTK ') do set var=%%a
awk "BEGIN {printf \"GPSID : \" }" >out.txt
echo %var% >>out.txt
This code basicly does what I wanted to do.
这段代码基本上做了我想做的事情。
You are great Thanks !!!!!
你很棒谢谢!!!!!
回答by Patrick Cuff
If you need to recurse through the output of the command, you can use for /f
. Something like:
如果您需要通过命令的输出递归,您可以使用for /f
. 就像是:
for /f "usebackq" %%L in (`awk '/GPSID/ {print }' gora.RTK`) do (
awk 'BEGIN {printf "Numer seryjny : " %%L,}' >> out.txt
)
回答by Autodidact
How about ...
怎么样 ...
for /f "tokens=*" %%a in ('echo Hello World') do set var=%%a
for /f "tokens=*" %%a in ('echo Hello World') do set var=%%a
NOTE: use %a instead of %%a when trying on the command line else keep it as %%a if using in a batch file.
注意:在命令行上尝试时使用 %a 而不是 %%a ,如果在批处理文件中使用,则将其保留为 %%a 。
Where 'echo Hello World' is the command whose output you want to capture and "var" is the name of the variable where the output will be stored.
其中“echo Hello World”是您要捕获其输出的命令,“var”是将存储输出的变量的名称。