newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: lyl on May 03, 2019, 04:51:43 AM

Title: How to run a dos command in win7 console by newlisp
Post by: lyl on May 03, 2019, 04:51:43 AM
I want to run the dos command in win7 console by newlisp "exec" to clear secreen like this:
(exec "cls")
but fails with a feedback ("f").

Why? And how to deal with this?



PS: Also (exec "color 0b") does not work.
Title: Re: How to run a dos command in win7 console by newlisp
Post by: rrq on May 03, 2019, 08:35:04 PM
Presumably the terminal control is done by writing control codes to stdout, and in that case you should rather use ! instead of exec. I.e.:
(! "cls")
(! "color 0b")

Alternatively at the interactive prompt, you can type the commands without parentheses and quoting by starting with the exclamation mark
> !cls
> !color 0b

The exec function runs a sub command and gathers its output lines into a list of strings, so to make this work with exec, you would need to print out those strings. Perhaps like this
(map println (exec "cls"))
(map println (exec "color 0b"))


Though, I don't use windows, so YMMV.
Title: Re: How to run a dos command in win7 console by newlisp
Post by: lyl on May 04, 2019, 07:35:00 AM
Perfect explanation! I learn a lot. Many thanks!