Very basic question.
How can I modify the output of a command (for example dir /b) to change its layout?
I'm not trying do do anything fancy (for now!) I would just like to start off by adding a blank line above the output of the command (so that there is a space between the resulting output and the preceding command that generated it).
The only examples that I've been finding online either seem to focus on output to text files, or more complex string manipulation.
Thanks
Modifying displayed output of commands
Moderator: DosItHelp
Re: Modifying displayed output of commands
You can't. The output of commands is given by their program code and was defined by their developers. In your case you can simply prepend a blank line using ECHO. If you want to do more than this you have to parse the output in a FOR /F loop and reassemble it in a way you want it to look like.
Steffen
Code: Select all
echo(&dir /b
Steffen
Re: Modifying displayed output of commands
I did try using the echo command previously, but the way that I was using it caused the blank line to always be added after the list of directories instead of before it.
However, your method works perfectly.
Many thanks.
However, your method works perfectly.
Many thanks.
Re: Modifying displayed output of commands
There's one more issue.
I was wanting to use this command as a Doskey macro, but when it's run as a macro it doesn't work (no directories are listed).
Perhaps that's because echo and dir are two separate commands and so Doskey expects $T to be added somewhere. I've tried adding $T in a few places, but it's still not working.
Any ideas on how to address this please?
I have one other question regarding Doskey macros, but it's unrelated to this particular topic, so I'll ask it in a separate thread.
I was wanting to use this command as a Doskey macro, but when it's run as a macro it doesn't work (no directories are listed).
Code: Select all
ls=echo(&dir /b
Perhaps that's because echo and dir are two separate commands and so Doskey expects $T to be added somewhere. I've tried adding $T in a few places, but it's still not working.
Any ideas on how to address this please?
I have one other question regarding Doskey macros, but it's unrelated to this particular topic, so I'll ask it in a separate thread.
Re: Modifying displayed output of commands
The & needs to be escaped by ^ for parsing it literally in the assignment.
Steffen
Code: Select all
doskey ls=echo(^&dir /b
Steffen
Re: Modifying displayed output of commands
Great!
Thanks very much.
Thanks very much.