0

I am writing a batch file in VS Code and I have a question. What are the ways to insert a non-printable character other than copying it from somewhere.

enter image description here

I have tried Alt+27, Alt+027, Alt+001b... but it doesn't work.

The question is not only in terms of echo, but in general about VSC. What are the possibilities to insert a non-printable character in VS Code? In the command line console, I can do this:

enter image description here

where ^[ is the non-printable Esc character typed in Alt+027. But how to do this in VSC when there is a need to insert a non-printable character? Alternatively, I can always write an extension for VSC that will open, copy and paste such characters, but it is useful when it is not possible to simply print them.

IPcorp
  • 23
  • 6
  • Does this answer your question? [Is it possible to echo some non-printable characters in batch/cmd?](https://stackoverflow.com/questions/21367518/is-it-possible-to-echo-some-non-printable-characters-in-batch-cmd) – OldProgrammer Dec 25 '22 at 01:51
  • Thank you for the answer. I added and corrected the question. – IPcorp Dec 25 '22 at 10:12

1 Answers1

-1

It's not a good idea to have non-printable characters in a text file. You can use the escape sequence \e instead:

echo "\e[32m color green \e[0m"
Guillaume Brunerie
  • 4,676
  • 3
  • 24
  • 32
  • Hmm, maybe I'm doing something wrong. I am working on windows 11. I created a batch file with one line `echo "\e[32m color green \e[0m"`. After running it, I just got the output `"\e[32m color green \e[0m"`. – IPcorp Dec 25 '22 at 14:35
  • Hmm, I guess you have a different shell, try `\033` instead of `\e`. – Guillaume Brunerie Dec 25 '22 at 20:13
  • `echo "\033[32m color green \033[0m"` outputs `"\033[32m color green \033[0m"`. Perhaps something is wrong with my console, and I need to install some library. Anyway, I solved the problem by using a non-printable character. Thank you for your answer, but the question is more whether there is any possibility in VSC to print a non-printable character, as is done in the console, if such a need arises. – IPcorp Dec 26 '22 at 00:28
  • What if you use `printf` instead of `echo`? – Guillaume Brunerie Dec 26 '22 at 08:02