Skip to content

Instantly share code, notes, and snippets.

@schwern
Created July 6, 2009 22:40
Show Gist options
  • Save schwern/141739 to your computer and use it in GitHub Desktop.
Save schwern/141739 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdlib.h>
/*
* Meant to mimic the shell command
* exec perl -Mperl5i "$@"
*
* This is a C program so it works in a #! line.
*/
int main (int argc, char* argv[]) {
int i;
/* This filename is not actually hard coded, the file is generated */
const char* perl_cmd = "/usr/local/perl/5.10.0/bin/perl";
char* perl_args[argc+1];
perl_args[0] = argv[0];
perl_args[1] = "-Mperl5i";
for( i = 1; i < argc; i++ ) {
perl_args[i+1] = argv[i];
}
/* Argument array to execv must
* terminated by a null pointer
*/
perl_args[argc+1] = (char *)NULL;
return execv( perl_cmd, perl_args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment