How to use cmd commmands like cls in scala?

I tried the way in stack overflow like this:
println("\u001b[2J")
but is seems won’t work! who can give me the code?

The code you’ve given works fine for me. As you are mentioning cmd and cls, are you using an older version of the Windows terminal? cmd.exe did not support ansi escape sequences until a windows 10 update and hasn’t enabled it by default.

So you either have to use a different terminal or change the settings of yours. If that isn’t possible, you’ll probably have to run “cls” as an external command, something like

import sys.process._
"cls".!!

(no guarantee on this working, I don’t have a Scala setup on Windows)

PS: for future posts: you can enable code formatting by enclosing your code in backticks, e.g. `code`, or triple backticks (with an optional language to highlight) for multiline code like this:
```scala
long code here
```

2 Likes