【问题标题】:Stripping ^M from output of cygwin programs从 cygwin 程序的输出中去除 ^M
【发布时间】:2013-11-09 00:51:35
【问题描述】:

我最近安装了 cygwin-x86_64,以及来自 http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip 的 gtk 和来自 http://protz.github.io/ocaml-installer/ 的 ocaml。每当我从“为 cygwin 预编译”的二进制文件(例如 ocaml 或 gtk)运行命令时,它都会在输出的末尾附加一个 ^M。例如,

$ ocamlc -where > foo; cat -v foo
D:/OCaml/lib^M

我该如何解决这个问题?

更新:如果我将二进制文件复制到 ~/(或其他一些 cygwin 路径),那么我不会得到 ^M 输出。它仅在二进制文件位于 MS DOS 位置时发生。有没有办法在不移动我的二进制文件的情况下解决这个问题?

运行mount 给出

$ mount D:/cygwin64/bin on /usr/bin type ntfs (binary,auto) D:/cygwin64/lib on /usr/lib type ntfs (binary,auto) D:/cygwin64 on / type ntfs (binary,auto) C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto) D: on /cygdrive/d type ntfs (binary,posix=0,user,noumount,auto) E: on /cygdrive/e type ntfs (binary,posix=0,user,noumount,auto) Y: on /cygdrive/y type afs (binary,posix=0,user,noumount,auto) Z: on /cygdrive/z type afs (binary,posix=0,user,noumount,auto)

【问题讨论】:

    标签: windows cygwin ocaml newline


    【解决方案1】:

    ^M 是Carriage Return,在 Windows 中使用,但在类 Unix 系统中不使用。使用 sed、tr 或您喜欢的工具从文件中删除 CR。 如果您在 windows 命令行中,那么

    tr -d '\r'  < foo.txt > bar.txt
    sed -e 's/\r//g' foo.txt > bar.txt
    

    如果您使用的是启用 vi 模式的终端,那么

    tr -d '^M'  < foo.txt > bar.txt
    sed -e 's/^M//g' foo.txt > bar.txt
    

    ^M可以通过Ctrl+M键输入

    【讨论】:

    • 我宁愿不必去编辑所有./configure 文件和我想要构建的每一位软件的所有 Makefile 以去除这些回车。
    【解决方案2】:

    对我来说,protz 混合使用 cygwin 和 ocaml-installer 听起来是错误的。最后一个是用于本机 Windows(并且在该安装程序中 cygwin 仅用于提供 shell)。如果您想在 cygwin 中使用 ocaml(带有 cygwin gcc 编译器和库),那么您必须从 cygwin 存储库(通过 cygwin-setup.exe)安装 ocaml。原生 windows 程序和 cygwin 编译程序之间是有区别的,你很难将它们混合起来进行开发..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 2016-06-11
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多