我可以将命令的输出保存在批处理脚本变量? [英] Can I store the output of a command in a variable in batch scripting?

查看:491
本文介绍了我可以将命令的输出保存在批处理脚本变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想DIR一个文件夹,在变量获得* .csv的文件的所有名字。

I want to dir a folder and get in a variable all the names of the *.csv files.

有谁知道我能做到这一点?

Does anyone know how can I do this?

推荐答案

使用bash,你可以试试:

Using Bash you can try:

dirlist=`ls -1 *.csv`
echo "$dirlist"

在窗口中,您可以阅读以下Q和A:

Under windows you can read the following Q and A:

<一个href=\"http://stackoverflow.com/questions/889518/windows-batch-files-how-to-set-a-variable-with-the-result-of-a-command\">Windows批处理文件:如何用命令的结果设置一个变量

是这样的:

for /f "delims=" %%a in ('dir') do @set foobar=%%a

更改'目录'你想要什么。我没有Windows机器附近,所以无法测试。

Change 'dir' to what you want. I have no windows machine close by, so cannot test.

这篇关于我可以将命令的输出保存在批处理脚本变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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