I want to print the output of a program in MS-DOS so I wrote a .bat file that says:
cls
ruby foo.rb
But the output - as it appears on my command prompt - looks like this:
c:\workspace>ruby foo.rb
foo output
c:\workspace>
I wanted to insert a newline into the output using MS-DOS because I don't want to pollute my Ruby code with anything not related to what the code is supposed to be doing.
The only commands in MS-DOS that look like what I want are 'type' and 'print' but both are for printing files.
I tried creating a text file with two blank lines and outputting it using the 'type' command but it looks messy.
Any ideas would be appreciated.
echo.
will produce a new line.
So your script should look something like this:
@ECHO OFF
cls
echo.
ruby foo.rb
Even if here are 4 answers with the same tip to use ECHO.
, it's not the best solution!
There are two drawbacks.
It's slowECHO.
is ~10 times slower than a normal echo
command, that's because ECHO.
will force a disk access
It can fail
If a file exists with the name ECHO
(without extension) then each ECHO.
command will result in a file not found error, instead of echoing an empty line.
But what do you can do then?
For a simple empty line, there are many working ways.
echo+
echo=
echo;
echo,
echo:
echo(
But sometimes you want a secure way to echo the content of a variable even if the variable is empty or contain odd content like /?
or \\..\..\windows\system32\calc.exe
.
ECHO<character>%variable%
echo=/?
echo;/?
echo,/?
echo:\\..\..\windows\system32\calc.exe
Then the most commands will fail, only ECHO(
works in any situation.
It looks a little bit strange, but it works and it does not need nor make any trouble with a closing bracket.
how about:
@echo off
cls
echo.
ruby foo.rb
echo.
bye
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With