Modifying displayed output of commands

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Modifying displayed output of commands

#1 Post by Quisquose » 22 Jul 2017 06:33

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).

Image

The only examples that I've been finding online either seem to focus on output to text files, or more complex string manipulation.

Thanks

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Modifying displayed output of commands

#2 Post by aGerman » 22 Jul 2017 06:43

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.

Code: Select all

echo(&dir /b
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

Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Re: Modifying displayed output of commands

#3 Post by Quisquose » 22 Jul 2017 07:16

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.

Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Re: Modifying displayed output of commands

#4 Post by Quisquose » 22 Jul 2017 07:40

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).

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Modifying displayed output of commands

#5 Post by aGerman » 22 Jul 2017 07:54

The & needs to be escaped by ^ for parsing it literally in the assignment.

Code: Select all

doskey ls=echo(^&dir /b

Steffen

Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Re: Modifying displayed output of commands

#6 Post by Quisquose » 22 Jul 2017 08:07

Great!

Thanks very much.

Post Reply