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:
  • 919 Vote(s) - 3.41 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows batch: echo without new line

#11
You can suppress the new line by using the set /p command. The set /p command does not recognize a space, for that you can use a dot and a backspace character to make it recognize it. You can also use a variable as a memory and store what you want to print in it, so that you can print the variable instead of the sentence. For example:

@echo off
setlocal enabledelayedexpansion
for /f %%a in ('"prompt $H & for %%b in (1) do rem"') do (set "bs=%%a")
cls
set "var=Hello World! :)"
set "x=0"

:loop
set "display=!var:~%x%,1!"
<nul set /p "print=.%bs%%display%"
ping -n 1 localhost >nul
set /a "x=%x% + 1"
if "!var:~%x%,1!" == "" goto end
goto loop

:end
echo.
pause
exit

In this way you can print anything without a new line. I have made the program to print the characters one by one, but you can use words too instead of characters by changing the loop.

In the above example I used "enabledelayedexpansion" so the set /p command does not recognize "!" character and prints a dot instead of that. I hope that you don't have the use of the exclamation mark "!" ;)
Reply

#12
Sample 1: This works and produces Exit code = 0. That is Good.
Note the "." , directly after echo.
>C:\Users\phife.dog\gitrepos\1\repo_abc\scripts #
>@echo.| set /p JUNK_VAR=This is a message displayed like Linux echo -n would display it ... & echo %ERRORLEVEL%

This is a message displayed like Linux echo -n would display it ... 0

Sample 2: This works *but* produces Exit code = 1. That is Bad.
Please note the lack of ".", after echo. That appears to be the difference.
>C:\Users\phife.dog\gitrepos\1\repo_abc\scripts #
>@echo | set /p JUNK_VAR=This is a message displayed like Linux echo -n would display it ... & echo %ERRORLEVEL%

This is a message displayed like Linux echo -n would display it ... 1
Reply

#13
> From [here][1]

<nul set /p =Testing testing

and also to echo beginning with spaces use

echo.Message goes here

[1]:

[To see links please register here]

Reply

#14
DIY `cw.exe` (console write) utility
=
If you don't find it out-of-the-box, off-the-shelf, you can DIY. With this `cw` utility you can use every kind of characters. At least, I'd like to think so. Please stress-test it and let me know.

Tools
-

All you need is [.NET](

[To see links please register here]

) installed, which is very common nowadays.

Materials
-
Some characters typed/copy-pasted.

Steps
-
1. Create `.bat` file with the following content.

<!-- -->

/* >nul 2>&1

@echo off
setlocal

set exe=cw
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*csc.exe"') do set "csc=%%v"

"%csc%" -nologo -out:"%exe%.exe" "%~f0"

endlocal
exit /b %errorlevel%

*/

using System;

namespace cw {
class Program {
static void Main() {
var exe = Environment.GetCommandLineArgs()[0];
var rawCmd = Environment.CommandLine;
var line = rawCmd.Remove(rawCmd.IndexOf(exe),exe.Length).TrimStart('"');
line = line.Length < 2 ? "\r" : line.Substring(2) ;
Console.Write(line);
}
}
}

2. Run it.

3. Now you have a nice 4KB utility so you can delete the `.bat`.

Alternatively, you can insert this code as a subroutine in any batch, send the resulting `.exe` to `%temp%`, use it in your batch and delete it when you're done.

How to use
-

If you want write something without new line:
`cw Whatever you want, even with "", but remember to escape ^|, ^^, ^&, etc. unless double-quoted, like in "| ^ &".`

If you want a carriage return (going to the beginning of the line), run just
`cw`

So try this from command line:

for /l %a in (1,1,1000) do @(cw ^|&cw&cw /&cw&cw -&cw&cw \&cw)
Reply

#15
I made a function out of @arnep 's idea:

> echo|set /p="Hello World"



**here it is:**

:SL (sameline)
echo|set /p=%1
exit /b

Use it with `call :SL "Hello There"`
<br> I know this is nothing special but it took me so long to think of it I figured I'd post it here.
Reply

#16
Inspired by the answers to this question, I made a simple counter batch script that keeps printing the progress value (0-100%) on the same line (overwritting the previous one). Maybe this will also be valuable to others looking for a similar solution.

**Remark**: The `*` are non-printable characters, these should be entered using [`Alt` + `Numpad 0` + `Numpad 8`] key combination, which is the `backspace` character.

```
@ECHO OFF

FOR /L %%A in (0, 10, 100) DO (
ECHO|SET /P="****%%A%%"
CALL:Wait 1
)

GOTO:EOF

:Wait
SET /A "delay=%~1+1"
CALL PING 127.0.0.1 -n %delay% > NUL
GOTO:EOF
```
Reply

#17
<h3>Echo with preceding space and without newline</h3>

As stated by [Pedro][1] earlier, echo without new line and with preceding space works (provided "9" is a true [BackSpace]).

<nul set /p=.9 Hello everyone

I had some issues getting it to work in Windows 10 with the new console but managed the following way.<br>
In CMD type:

echo .◘>bs.txt

I got "◘" by pressing [Alt] + [8]<br>
(the actual symbol may vary depending upon codepage).

Then it's easy to copy the result from "bs.txt" using Notepad.exe to where it's needed.

@echo off
<nul set /p "_s=.◘ Hello everyone"
echo: here


[1]:

[To see links please register here]

Reply

#18

Use EchoX.EXE from the terrific "Shell Scripting Toolkit" by [Bill Stewart][1]<br>
How to suppress the linefeed in a Windows Cmd script:

@Echo Off
Rem Print three Echos in one line of output
EchoX -n "Part 1 - "
EchoX -n "Part 2 - "
EchoX "Part 3"
Rem
gives:

Part 1 - Part 2 - Part 3
{empty line}
d:\Prompt>

The help for this usage is:

Usage: echox [-n] message
-n Do not skip to the next line.
message The text to be displayed.

The utility is smaller than 48K, and should live in your Path. More things it can do:<br />- print text without moving to the next line<br />- print text justified to the left, center, or right, within a certain width<br />- print text with Tabs, Linefeeds, and Returns<br />- print text in foreground and background colors

The Toolkit includes twelve more great scripting tricks.<br/>
[The download page][2] also hosts three other useful tool packages.


[1]: /users/2102693/bill-stewart
[2]:

[To see links please register here]

Reply

#19
With jscript:

@if (@X)==(@Y) @end /*
@cscript //E:JScript //nologo "%~nx0" %*
@exit /b %errorlevel%
*/if(WScript.Arguments.Count()>0) WScript.StdOut.Write(WScript.Arguments.Item(0));

if it is called write.bat you can test it like:

call write.bat string & echo _Another_String_


If you want to use powershell but with cmd defined variables you can use:

set str=_My_StrinG_
powershell "Write-Host -NoNewline ""%str%"""" & echo #Another#STRING#
Reply

#20
I found this simple one-line batch file called "EchoPart.bat" to be quite useful.

@echo | set /p=%*

I could then write something like the line below even on an interactive CMD line, or as part of a shortcut. It opens up a few new possibilities.

echopart "Hello, " & echopart "and then " & echo Goodbye

[![enter image description here][1]][1]

And if you're using it in batch files, the texts can be got from parameter variables instead of immutable strings. For instance:

@echopart Hello %* & @echo , how are you?

So that executing this line in "SayHello.bat" allows:

[![enter image description here][2]][2]

or even...

[![enter image description here][3]][3]

Have a play, and have fun!

[1]:

[2]:

[3]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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