Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 663 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print a newline in an MS-DOS script?

#1
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.


Reply

#2
Try this

echo.
Reply

#3
Use the echo command followed by a period to display a new line in an MS-DOS batch file:

echo.
Reply

#4
how about:

@echo off
cls
echo.
ruby foo.rb
echo.

bye
Reply

#5
I'm not clear on what you want here, but maybe this will help.

If you want the output sent to somewhere else, use the dos output "pipe".

ruby foo.rb > out.txt

will output the output of the ruby command to the out.txt file.

If you want to control the output, use ECHO.

@ECHO OFF/ON //turns off/on command output
ECHO "Blah" //writes "Blah" to the console.
ECHO. //writes a blank line to the console.



Reply

#6
Even if here are 4 answers with the same tip to use `ECHO.`, it's not the best solution!

There are two drawbacks.

1. It's slow
`ECHO.` is ~10 times slower than a _normal_ `echo` command, that's because `ECHO.` will force a disk access

2. 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.
Reply

#7
I agree with jeb. "echo(" is definitely faster and does not invoke a file access. Just try it and you'll know for yourself. Here is a little test you might want to try out.

Create a file named "echo" and in the same directory create a test.bat or test.cmd file have the following content in the script:

@echo off
echo %time%
echo.
echo Hello, World
echo.
echo.
echo What time is it?
echo.
echo It's Miller Time!
echo.
echo.
echo CHEERS!
echo.
echo %time%

Run the newly created batch file. What do you get? A bunch of error messages when a file "echo" exists in the same directory.

Now, delete the "echo" file.

On my system, it took approximately .05 seconds from start to finish using the "echo." method due to file access taking place.

Now, replace all "echo." in the test file above with "echo(" and run it again.

It takes approximately .01 seconds from start to finish using the "echo(" statement.

Final test, reintroduce a file called "echo" in the same directory and run the batch one last time.

No error messages.

QED
Reply

#8
`echo.` will produce a new line.

So your script should look something like this:

@ECHO OFF
cls
echo.
ruby foo.rb
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through