On Wed, 2005-06-29 at 01:47 +0100, Chris Benson wrote:
> Hi all,
>
> I'm starting to build a library (family?) of .sprogs. I was wondering how
> feasible it would be to make the saved .sprog files executable?
> That is: start the the saved files with some command like:
> #!/usr/bin/sprog --nogui --run -
Yes, I also considered that idea and didn't reach a conclusion as to
whether it was desirable or not. I wondered if emailing such a file to
someone would constitute a security risk and decided it probably
wouldn't (at least no worse than mailing a .sh, .exe or .bat).
> Adding that to the .sprog file doesn't seem to interfere with the YAML.
> But it looks like the .sprog is run by the shell:
>
> $ ./t1.sprog
> ./t1.sprog: line 2: -: command not found
> ./t1.sprog: line 3: -: command not found
> ./t1.sprog: line 4: -: command not found
Yes, I vaguely recall that you can't use an interpreted program as the
interpreter in a shebang line. Or if you can, some non-portable tricks
are required.
What you could do is compile a C wrapper like the following
(runsprog.c):
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
char *args[] = {"sprog", "--nogui", "", NULL};
args[2] = argv[argc-1];
execvp("/usr/bin/sprog", args);
return(1);
}
Compile it with 'make runsprog' and install it as say
/usr/local/bin/runsprog and then use the shebang line:
#!/usr/local/bin/runsprog
Note, any options in the shebang line would be ignored by this simple
wrapper. Options in shebang lines are treated differently by different
systems so for expediency I ignored them and hardcoded '--nogui'.
That small snippet severely tested my C 'skills' but if someone wanted
to turn it into a more general solution then go for it.
Regards
Grant
|