(我知道这是一个基本/新手错误。但我怀疑我是第一个或最后一个犯这个错误的人......所以我会在这里记录它,以便像我这样的未来笨蛋可以用谷歌搜索它。)
这些脚本冻结是因为它们实际上是 shell 脚本。这些 shell 脚本实际上是在运行import 命令行程序...由ImageMagick 包提供:
$ sh freeze.hs
C-c
$ which import
/usr/bin/import
$ man import | head -10
... import - saves any visible window on an X server and outputs it as an image file.
$ import screenshot.ps
... and here notice the mouse icon changes to a cross-hair icon ...
... so then press the mouse button to finish this operation ...
$ file screenshot.ps
screenshot.ps: PostScript document text conforming DSC level 3.0, Level 1
感谢 ImageMagick 工作人员提供了一个不错的、无声的命令行操作。
至少在各种基于Linux的操作系统上,这些脚本触发import命令行程序的操作。 BSD、Windows、MacOS 等可能会有不同的响应。
下面是使用 Python 解释器和ghc 编译器对脚本的正确操作:
$ python freeze.py
hello
$ runghc freeze.hs
"hello"
或者,包括#! shebang:
$ ls -l no_freeze.py
-rwx------ 1 rick rick 46 Oct 27 11:44 no_freeze.py
$ cat no_freeze.py
#!/usr/bin/env python
import re
print "hello"
$ ./no_freeze.py
hello
Haskell 也是如此:
$ ls -l no_freeze.hs
-rwx------ 1 rick rick 68 Oct 27 11:26 no_freeze.hs
$ cat no_freeze.hs
#!/usr/bin/env runghc
import Text.Regex.Posix
main = print "hello"
$ ./no_freeze.hs
"hello"
在我的 MacOS 计算机上,我收到此错误是因为我的 X11 设置的某些部分未完成。对于那些没有安装 X11 的人,我想你会得到 command not found 错误。
$ import screenshot
Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-02 http://www.imagemagick.org
...
import: delegate library support not built-in `' (X11) @ error/import.c/ImportImageCommand/1297.