nmake - 如何强制 echo 命令输出制表符?

发布于 2024-07-18 08:01:21 字数 206 浏览 7 评论 0原文

如何强制 echo 命令在 MS nmake makefile 中输出制表符? 在 echo 命令之后直接插入到字符串中的逐字制表符会被 nmake 删除,并且不会显示在输出文件中。

all :
    @echo I WANT TO OUTPUT THE <TAB> CHARACTER HERE! > output.txt

How to force echo command to output a tab character in MS nmake makefile?
Verbatim tabs inserted right into a string after echo command are removed by nmake and don't show up in the output file.

all :
    @echo I WANT TO OUTPUT THE <TAB> CHARACTER HERE! > output.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一桥轻雨一伞开 2024-07-25 08:01:21

您可以使用带有 TAB 字符的变量。 将此行放入您的 .bat 文件中:

set tab=[从键盘中敲击 TAB 字符]
echo a%tab%b>yourfile.txt

这样做,yourfile.txt 将包含文本 a[TAB]b

You can use a variable with TAB char. Put this lines in your .bat file:

set tab=[stroke TAB char from your keyboard]
echo a%tab%b>yourfile.txt

Doing so, yourfile.txt will have text a[TAB]b

捶死心动 2024-07-25 08:01:21

作为解决方法,您可以创建一个包含制表符的文件,名为 input.txt(不使用 nmake),然后输入:

all :
    @copy /b input.txt output.txt

As a workaround, you can create a file containing the tab character, named input.txt (not using nmake), and then say:

all :
    @copy /b input.txt output.txt
梦罢 2024-07-25 08:01:21

我假设您已经尝试过将选项卡放在引号内?

all:
    @echo "<TAB>" > output.txt

I assume you already have tried to put the tab inside quotes?

all:
    @echo "<TAB>" > output.txt
陌伤浅笑 2024-07-25 08:01:21

DOS 和 Windows 在本机批处理文件中提供丑陋的文本支持:)。

这是完成任务的好方法:

  1. 安装Python解释器
  2. 编写简单的脚本,该脚本将具有指定代码的字符附加到文件
  3. 调用脚本中的任何位置:)

简单脚本:

'''
append_char.py - appends character with specified code to end of file

Usage:  append_char.py  filename charcode

'''
import os
import sys

filename = sys.argv[1]
assert os.path.exists(filename)

charcode = int(sys.argv[2])
assert 0 <= charcode <= 255

fh = open(filename, 'ab')
fh.seek(0, os.SEEK_END)
fh.write(chr(charcode))

fh.close()

使用批处理文件中的此脚本,您可以在Universe中创建任何可能的文件:)

DOS and Windows have ugly text support in native batch files :).

Here is nice way to do your task:

  1. install Python interpretator
  2. write simple script which appends character with specified code to file
  3. call script wherever you want :)

Simple script:

'''
append_char.py - appends character with specified code to end of file

Usage:  append_char.py  filename charcode

'''
import os
import sys

filename = sys.argv[1]
assert os.path.exists(filename)

charcode = int(sys.argv[2])
assert 0 <= charcode <= 255

fh = open(filename, 'ab')
fh.seek(0, os.SEEK_END)
fh.write(chr(charcode))

fh.close()

using this script from batch file you can create any possible file in universe :)

空城之時有危險 2024-07-25 08:01:21
output.txt:
    <<output.txt
I WANT TO OUTPUT THE <TAB> CHARACTER HERE!
<<KEEP

当然, 在这里代表一个文字制表符。

output.txt:
    <<output.txt
I WANT TO OUTPUT THE <TAB> CHARACTER HERE!
<<KEEP

<TAB> represents a literal tab character here of course.

岁月静好 2024-07-25 08:01:21

我有同样的需要。 我使用角色周围的引号来使用答案,并且更进一步。

{tab} 表示在文本编辑器中按键盘 Tab 键。

SET tab="{tab}"

SET tab=%tab:~1,1%

第二行从引用的字符串中提取中间字符。

现在您可以将 %tab% 变量与 ECHO 一起使用,我怀疑,在其他需要它的地方也可以使用。

ECHO %tab%此文本是缩进的,前面有一个制表符。

我怀疑这种技术也可以用于其他有问题的角色。

I had the same need. I used the answer using the quotes around the character and just took it one step further.

{tab} means pressing the keyboard tab key in the text editor.

SET tab="{tab}"

SET tab=%tab:~1,1%

The second line extracts the middle character from the quoted string.

Now you can use the %tab% variable with ECHO and, I suspect, anywhere else it's needed.

ECHO %tab%This text is indented, preceded by a tab.

I suspect this technique could be used with other problem characters as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文