Two newlines in one echo command
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.
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 and echo
would have gobbled it up.
How about this:
app.exe -args "file" | (echo. & echo Writing "file")
Ok, in your case, there are multiple problems.
Normally you can echo a line feed with a small trick
setlocal EnableDelayedExpansion
set LF=^
rem Two empty lines are neccessary for the LF creation
rem In the variable <lf> is one line feed character
echo Line1!lf!Line2
------ OUTPUT -----
Line1
Line2
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
app.exe -args "file" | (echo. & echo Writing "file")
Writing "file"...
_______________
|app for work |
|ver:2 10/2009|
|_____________|
instead of
_______________
|app for work |
|ver:2 10/2009|
|_____________|
Writing "file"...
You can test it (on the cmdline)
echo one >&2 | echo two
In the most cases the output is:
one
two
But not always!
you might want to group your two echo commands:
app.exe -args "file" & ( echo ""; echo Writing "file" )
What about
echo -e "`app.exe -args \"file\"` \n Writing file"
精彩评论