从cygwin程序的输出中剥离^ M.

时间:2013-11-09 00:51:35

标签: windows cygwin ocaml newline

我最近安装了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)

2 个答案:

答案 0 :(得分:0)

^ 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-mode的终端,那么

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

可以通过按键Ctrl + M

输入^ M.

答案 1 :(得分:0)

对我来说,通过protz混合使用cygwin和ocaml-installer听起来是错误的。最后一个用于本机窗口(在安装程序中,cygwin仅用于提供shell)。如果你想在cygwin中使用ocaml(使用cygwin gcc编译器和库),那么你必须从cygwin存储库安装ocaml(通过cygwin-setup.exe)。本机Windows程序和cygwin编译程序之间存在差异,您很难成功地将它们混合用于开发..

相关问题