[Openmcl-devel] Running ccl as a shebang script
Tim Bradshaw
tfb at tfeb.org
Thu Feb 16 03:16:25 PST 2017
What I do is something like this:
#!/bin/sh -
exec ccl -Q -b <<EOF
(print "hi")
EOF
Which I think is perhaps not as robust, but works (note this depends on my ccl wrapper but that's mostly just a thing to avoid having to know what obscure path the executable is sitting in & to support recompiling &c).
--tim
> On 16 Feb 2017, at 00:20, Ron Garret <ron at flownet.com> wrote:
>
> Running ccl as a shebang script is not a supported feature. It turns out that it’s possible to do it, but it requires some horrible hackery: you have to define a reader macro that treats #! as a comment delimiter, and you have to put that in your ccl-init file. That seemed too ugly to me, so I wrote a little C program that reads past the first line of the script and pipes the rest into ccl’s stdin. That seemed like a cleaner solution. Just in case anyone else cared about this I thought I’d share the code:
>
>
> ➔ cat cclsh.c
> #include <stdlib.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <fcntl.h>
>
> char *args[] = {"cclsh", "-Q", "-b"};
>
> int main(int argc, char *argv[], char *envp[]) {
> if (argc!=3) {
> fprintf(stderr, "Usage: %s [path-to-ccl-executable] [path-to-script]",
> argv[0]);
> exit(-1);
> }
> int fd = open(argv[argc-1], O_RDONLY);
> char c = ' ';
> while (c!='\n') read(fd, &c, 1);
> fclose(stdin);
> dup(fd);
> close(fd);
> execve(argv[1], args, envp);
> }
>
>
> Example:
>
> ➔ cat test
> #!cclsh /Users/ron/devel/ccl/active/dx86cl64
> (list 1 2 3)
> ➔ ./test
> (1 2 3)
>
> rg
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list