Best way to use xterm ESC-sequences in scripts in Cmd e.g. bat, js, vbs, pl, py? #49

Open
opened 2026-01-30 21:40:38 +00:00 by claunia · 0 comments
Owner

Originally created by @mobluse on GitHub (Jan 21, 2018).

  • Your Windows build number:
    Microsoft Windows [Version 10.0.17074.1002]

  • What you're doing and what's happening:
    I want to use ESC-sequences in bat-, js-, vbs, pl, py-files in Cmd, but don't know how to switch so that they are used. I tried e.g. a program called input.js:

WScript.Echo("\x1B[1mEnter something\x1B[0m");
WScript.Echo("You entered " + WScript.StdIn.ReadLine());

And run it using cscript input.js //NoLogo. This prints:

Enter something
hello
You entered hello

  • What's wrong / what should be happening instead:
    Enter something
    hello
    You entered hello

I can cure this by using start /wait /b before the command:
start /wait /b cscript input.js //NoLogo
Enter something
hello
You entered hello

Is start /wait /b the best way to use ESC-sequences from https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences in a bat-, js- or vbs-program?

Originally created by @mobluse on GitHub (Jan 21, 2018). * Your Windows build number: Microsoft Windows [Version 10.0.17074.1002] * What you're doing and what's happening: I want to use ESC-sequences in bat-, js-, vbs, pl, py-files in Cmd, but don't know how to switch so that they are used. I tried e.g. a program called input.js: ``` WScript.Echo("\x1B[1mEnter something\x1B[0m"); WScript.Echo("You entered " + WScript.StdIn.ReadLine()); ``` And run it using `cscript input.js //NoLogo`. This prints: ``` Enter something hello You entered hello ``` * What's wrong / what should be happening instead: **`Enter something`** `hello` `You entered hello` I can cure this by using `start /wait /b` before the command: `start /wait /b cscript input.js //NoLogo` **`Enter something`** `hello` `You entered hello` Is `start /wait /b` the best way to use ESC-sequences from https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences in a bat-, js- or vbs-program?
claunia added the Product-ConhostIssue-QuestionArea-VTResolution-Answered labels 2026-01-30 21:40:38 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#49