On Tue, Oct 16, 2012 at 05:32:57PM +0200, Sven Van Caekenberghe wrote:
> 
> On 16 Oct 2012, at 16:13, David T. Lewis <[email protected]> wrote:
> 
> > If you don't want to do it in the VM, you can do it with a shell script.
> > Just make a 512 byte file that starts with the shebang line that you
> > want to use, prepend it to the saved image file (with /bin/cat) and set
> > file mode executable (chmod).
> 
> Well, I tried on my Ubuntu server, and I could't get it to work.
> 
> I have a Pharo 2.0 image and a little test script called run.st
> 
> $ cat run.st 
> NonInteractiveTranscript stdout install.
> !
> | webSocket |
> webSocket := ZnWebSocket to: 'ws://localhost:8080/ws-echo'.
> [ 
>   webSocket sendMessage: 'Pharo Smalltalk using Zinc WebSockets'.
>   Transcript show: webSocket readMessage; cr ] ensure: [ webSocket close ].
> !
> Smalltalk quitPrimitive.
> 
> I wrote another small Smalltalk script to generate the header (just to be 
> sure)
> 
> $ cat write-header.st 
> 'header.bin' asFileReference writeStreamDo: [ :stream | | line |
>       line := '#!!/home/ubuntu/smalltalk/bin/CogVM -vm-display-null 
> -vm-sound-null -plugins /home/ubuntu/smalltalk/bin/'.
>       stream 
>               binary; nextPutAll: line asByteArray; nextPut: 10; 
>               nextPutAll: (ByteArray new: 511 - line size) ].
> !
> Smalltalk quitPrimitive.
> 
> Now I have a 512 byte header that looks like this
> 
> $ hexdump -C header.bin 
> 00000000  23 21 2f 68 6f 6d 65 2f  75 62 75 6e 74 75 2f 73  |#!/home/ubuntu/s|
> 00000010  6d 61 6c 6c 74 61 6c 6b  2f 62 69 6e 2f 43 6f 67  |malltalk/bin/Cog|
> 00000020  56 4d 20 2d 76 6d 2d 64  69 73 70 6c 61 79 2d 6e  |VM -vm-display-n|
> 00000030  75 6c 6c 20 2d 76 6d 2d  73 6f 75 6e 64 2d 6e 75  |ull -vm-sound-nu|
> 00000040  6c 6c 20 2d 70 6c 75 67  69 6e 73 20 2f 68 6f 6d  |ll -plugins /hom|
> 00000050  65 2f 75 62 75 6e 74 75  2f 73 6d 61 6c 6c 74 61  |e/ubuntu/smallta|
> 00000060  6c 6b 2f 62 69 6e 2f 0a  00 00 00 00 00 00 00 00  |lk/bin/.........|
> 00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
> *
> 00000200
> 
> Then I concatenate the header and the working image
> 
> cat header.bin zinc.image > magic.image
> 
> and I copy the changes and make the image executable.
> 
> The image still works
> 
> $ /home/ubuntu/smalltalk/bin/CogVM -vm-display-null -vm-sound-null -plugins 
> /home/ubuntu/smalltalk/bin/ magic.image run.st
> Pharo Smalltalk using Zinc WebSockets
> 
> But not when run directly
> 
> $ ./magic.image 
> Segmentation fault (core dumped)
> 
> Any hints ?
> 

The parameters are not being passed to your VM in the way you expect. Here is
what the man page for bash says:

       If  the program is a file beginning with #!, the remainder of the first
       line specifies an interpreter for the program.  The shell executes  the
       specified interpreter on operating systems that do not handle this exe-
       cutable format themselves.  The arguments to the interpreter consist of
       a  single optional argument following the interpreter name on the first
       line of the program, followed by the name of the program,  followed  by
       the command arguments, if any.

I think there is some trick you can use to pass parameters, but I can't
recall the details. Maybe google can help.

Dave


Reply via email to