在Windows批处理中,Linux shell命令echo -n抑制输出末尾的换行符是什么?
其思想是在循环中的同一行上写入。
在Windows批处理中,Linux shell命令echo -n抑制输出末尾的换行符是什么?
其思想是在循环中的同一行上写入。
当前回答
从这里
<nul set /p =Testing testing
同时也从空间的使用开始呼应
echo.Message goes here
其他回答
我根据@arnep的想法做了一个函数:
echo|set /p="Hello World"
下面就是:
:SL (sameline)
echo|set /p=%1
exit /b
使用call:SL "Hello There" 我知道这没什么特别的,但我花了很长时间才想出来,所以我想我应该把它贴在这里。
受到这个问题答案的启发,我制作了一个简单的计数器批处理脚本,在同一行上打印进度值(0-100%)(覆盖前一行)。也许这对寻找类似解决方案的其他人也有价值。
注:*为不可打印字符,应使用[Alt + Numpad 0 + Numpad 8]组合键输入,即退格字符。
@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
我相信没有这样的选择。或者你可以试试这个
set text=Hello
set text=%text% world
echo %text%
Late answer here, but for anyone who needs to write special characters to a single line who find dbenham's answer to be about 80 lines too long and whose scripts may break (perhaps due to user-input) under the limitations of simply using set /p, it's probably easiest to just to pair your .bat or .cmd with a compiled C++ or C-language executable and then just cout or printf the characters. This will also allow you to easily write multiple times to one line if you're showing a sort of progress bar or something using characters, as OP apparently was.
DIY cw.exe(控制台编写)实用程序
如果你找不到现成的,你可以自己动手做。有了这个cw实用程序,你可以使用每一种字符。至少,我是这么想的。请对它进行压力测试,然后告诉我。
工具
你所需要的只是安装。net,这在当今非常普遍。
材料
输入/复制粘贴了一些字符。
步骤
用以下内容创建.bat文件。
/* >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);
}
}
}
运行它。 现在您有了一个很棒的4KB实用程序,可以删除.bat。
或者,您可以在任何批处理中插入此代码作为子例程,将生成的.exe发送到%temp%,在批处理中使用它,并在完成时删除它。
如何使用
如果你想写一些没有换行的东西: 任何你想要的,即使是"",但记住转义^|,^^,^&等,除非双引号,如"| ^& "。
如果你想要一个回车(回到行首),运行just 连续波
所以试试从命令行:
for /l %a in (1,1,1000) do @(cw ^|&cw&cw /&cw&cw -&cw&cw \&cw)