一个 echo 命令中有两个换行符
简而言之,我在 Windows XP/Windows 7 批处理文件中设置了一个最基本的文本进度指示器,该指示器在命令行工具工作时的输出之后写入,因为它看起来暂时没有执行任何操作。我通过在命令后传递简介来实现这一点,如下所示:
app.exe -args "file"|echo Writing "file"...
这会产生如下所示的结果:
_______________ |app for work | |ver:2 10/2009| |_____________| Writing "file"...
有没有办法在应用程序的输出和我的输出之间插入换行符?
我做过但失败的事情:
|echo.|echo |echo.|echo.|echo |echo.&echo.&echo |echo [alt+255/hex:FF/ÿ/EOL][same again] |echo -e \r\r (lol) |echo.. (nope!)
& 可能会延迟到应用程序执行其操作之后,到那时就为时已晚......我错过了什么吗?有可能吗?我知道这并不重要,但我很好奇。
Simply put, I've set a most basic text progress indicator in a Windows XP/Windows 7 batch file that writes just after a command line tool's output while it works, because it doesn't look like it does anything for a bit. I do so by piping the blurb after the command as such:
app.exe -args "file"|echo Writing "file"...
This results in something like the following:
_______________ |app for work | |ver:2 10/2009| |_____________| Writing "file"...
Is there a way to slip a newline in between the application's output and my output?
Things I've done and failed:
|echo.|echo |echo.|echo.|echo |echo.&echo.&echo |echo [alt+255/hex:FF/ÿ/EOL][same again] |echo -e \r\r (lol) |echo.. (nope!)
The &'s are probably delayed until after the application does its thing, and by then it's too late... Have I missed something? Is it even possible? I know this is not truly important, but I'm very curious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从您的示例中,我怀疑
app.exe
实际上将其输出发送到标准错误,而不是标准输出。否则,它的输出将被发送到管道,并且 echo 会吞噬它。这个怎么样:
From your example, I suspect that
app.exe
actually sends its output to standard error, rather than standard output. Otherwise its output would have been sent to the pipe andecho
would have gobbled it up.How about this:
好的,就您而言,存在多个问题。
通常,您可以通过一个小技巧来回显换行,
但在您的情况下,这不起作用,因为管道破坏了延迟扩展。
但是管道会产生更多问题,因为它启动两个异步任务。
实际上,您的 app.exe 作为任务 1 运行,而 echo 写入文件 作为任务 2 运行。
因此,任务 2 可能会在任务 1 之前执行,输出将是
你
可以测试它(在命令行上)
在大多数情况下,输出是:
但并非总是如此!
Ok, in your case, there are multiple problems.
Normally you can echo a line feed with a small trick
But in your case this doesn't work, because the pipe breaks the delayed expansion.
But the pipe will make more problems, as it starts two asynchronous tasks.
In reallity your app.exe runs as task1 and echo Writing file runs as task2.
So it can happen that task2 will be executed before task1, the output would be
instead of
You can test it (on the cmdline)
In the most cases the output is:
But not always!
您可能想要分组您的两个 echo 命令:
you might want to group your two echo commands:
怎么样
What about