在同一条线上呼应
我查看了您数据库之前的问题,我没有尝试回答,但我尝试了。
我想编写以下几行代码:
echo Executing backup....
backup procedure
echo Ok
但输出应该是:
Executing backup... Ok
这可能吗?!
I had a look at the previous questions of your db and I didn't try an answer, but I try.
I would like to write the following lines code:
echo Executing backup....
backup procedure
echo Ok
but the output should be:
Executing backup... Ok
That's possible?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我想你正在使用 dos/nt-batch。
可以使用 set /p 命令,因为 set /p 不会打印 CrLf
也可以使用 CR 字符擦除该行。
重要的是要知道一组 /p 前面的空白字符会被忽略(在 Vista 中,而不是在 XP 中),因此 !cr!必须放在后面或最后。
CR只能用delayedExpansion来显示,因为%cr%可以工作,但是CR字符在百分比扩展阶段(或直接在此阶段之后)被删除,但在延迟扩展阶段不会被删除。
仅使用一行显示的计数器示例
编辑:解释,如何创建变量
cr
(通过技巧完成)设置变量
X 变为单个点(字符本身不重要),通过
for /L %%c in (1,1,13) DO set X=!X:~0 重复成为 8188 个字符,4094!!X:~0,4094!
然后将变量、两个空格以及 CR 和 LF 回显到文件中
echo !X! > %temp%\cr.tmp
(注意!X!
和>
之间的两个空格以及自然行尾 echo 内部修正)我们现在有 8192 个字符,但数据缓冲区只能容纳 8191 个字符,因此最后一个字符(换行符)将被删除!
在下一行中
echo\>> %temp%\cr.tmp
,另一个CR/LF
组被追加到文件中(命令中的\
只是不输出任何内容,除了回车符返回和换行,因为echo
本身会输出ECHO is ON/OFF
),这一点很重要,因为单个CR
不能在行尾读取(稍后详细介绍)。因此该文件现在包含
<8188 .'s>
for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do 读取第二个标记,分隔符是标准空格和制表符,因此第二个标记只是一个
CR
,因为以下CR/LF
已作为标准行结尾被删除。最后,
endlocal
用于返回到不存在临时变量X
、c
和a
的环境(如将endlocal
放在括号中,它允许在endlocal
在括号末尾实际生效之前设置cr
(也可以写成asfor /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do endlocal&set cr=%%a&goto :eof
)另外
这是我创建 CR 角色的第一种方法,但它需要一些时间和一个临时文件。
后来我看到了一种从
copy /z
命令检索 CR 的更简单方法。I suppose you are using dos/nt-batch.
It is possible with the set /p command, because set /p doesn't print a CrLf
Also it's possible to erase the line with a CR character.
It's important to know that whitespace characters at the front of an set /p are ignored (in Vista, not in XP), so the !cr! has to placed later or at the end.
A CR can only be displayed with delayedExpansion, because %cr% works, but CR characters are removed in the percent expansion phase(or directly after this phase), but not in the delayed expansion phase.
Example of a counter which use only one line for displaying
EDIT: Explanation, how the variable
cr
is created (Done with a trick)After setting variable
X
to a single dot (the character itself is unimportant), it is repeated to become 8188 characters by way offor /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!
Then the variable, two spaces and both a CR and LF are echoed into a file with
echo !X! > %temp%\cr.tmp
(Notice the two spaces between the!X!
and the>
and the natural line endings echo amends internally)We now have 8192 characters, but the data buffer can only hold 8191 characters, so the last character (the linefeed) will be dropped!
In the next line
echo\>> %temp%\cr.tmp
, anotherCR/LF
set is appended to the file (the\
in the command is just to output nothing bar the carriage return and line feed, asecho
by it's self will outputECHO is ON/OFF
), that's important, as a singleCR
can't be read at the end of a line (More later).So the file now contains
<8188 .'s><SPACE><SPACE><CR><CR><LF>
The
for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do
reads the second token, the delimters are standard space and tab, so the second token is only a singleCR
, as the followingCR/LF
is removed as standard line ending.Finally the
endlocal
is used to return to an environment without the temporary variablesX
,c
anda
existing (As with theendlocal
in brackets, it allows the setting ofcr
before theendlocal
actually takes affect at the end of the brackets (could also be written asfor /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do endlocal&set cr=%%a&goto :eof
)Additionally
This was my first way to create a CR character, but it needs some time and a temporary file.
Later I saw a simpler method of retrieving the CR from a
copy /z
command.在 Posix 系统 (Linux) 上尝试一下,
在 Windows 上则困难得多。您将需要使用如下内容:
检查此帖子:http://www.pcreview.co.uk/forums/showpost.php?s=1a20b16775d915998b30bd76a0ec5d35&p=4432915&postcount=7。
Try this on Posix system (Linux)
It is much harder on Windows. You will need to use something like this:
Check this post: http://www.pcreview.co.uk/forums/showpost.php?s=1a20b16775d915998b30bd76a0ec5d35&p=4432915&postcount=7.
这有点黑客,但这里有一个 描述如何在 Windows 上执行此操作的文章。
从文章中来看,最终结果(根据您的设置进行编辑)如下所示:
It's a bit of a hack, but here is an article describing how to do it for Windows.
From the article, the final result (edited for your setup) looks like this:
我用 VBScript 做了类似的事情。
将此代码放入 EchoNoNewline.vbs 中:
从批处理文件中,使用如下脚本:
I've done something similar using a VBScript.
Put this code in EchoNoNewline.vbs:
From your batch file, use the script like this:
在 cmd 中管道之前的正斜杠如何删除 echo 的行结尾?
最好的建议是:
at What does a forward slash before a pipe in cmd do to remove the line ending of an echo?
the best suggestion is: