[Openmcl-devel] Running ccl as a shebang script
Ron Garret
ron at flownet.com
Wed Feb 15 16:20:18 PST 2017
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
More information about the Openmcl-devel
mailing list