Why does a simple Python / Haskell / etc program freeze / freeze upon import?

Why does this Python program freeze / freeze:

$ ls -l freeze.py -rwx------ 1 rick rick 24 Oct 27 11:40 freeze.py $ cat freeze.py import re print "hello" $ ./freeze.py Cc 

And why does this Haskell program also freeze and freeze:

 $ ls -l freeze.hs -rwxrw-r-- 1 rick rick 46 Oct 27 11:22 freeze.hs $ cat freeze.hs import Text.Regex.Posix main = print "hello" $ ./freeze.hs Cc 
+5
source share
1 answer

(I know this is a rudimentary mistake / newbie. But I doubt that I am the first or last person to make this mistake ... so I will write it here so that future klutzes like me can do it.)

These scripts freeze because they are really shell scripts. These shell scripts actually run the import ... command-line program provided by ImageMagick :

 $ sh freeze.hs Cc $ 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 

So my joy to the ImageMagick team is to provide a pleasant, silent command line experience.

At least on various Linux-based operating systems, these scripts start the import command line program. BSD, Windows, MacOS, etc. They can react differently.

The following is the correct script operation with the Python interpreter and the ghc compiler:

 $ python freeze.py hello $ runghc freeze.hs "hello" 

Or alternatively turn on #! 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 

And the same for 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" 

On my MacOS computer, I get this error because some of my X11 installation is not complete. For those who did not install X11, I assume that you will receive a command that did not find an error.

 $ 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. 
+9
source

Source: https://habr.com/ru/post/1272947/


All Articles