Created
May 10, 2010 01:43
-
-
Save exodist/395567 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main (int argc, char* argv[]) { | |
int i; | |
int pi; | |
const char* perl_cmd = "%s"; | |
char* perl_args[argc+1]; | |
char* dash_m = (char *)malloc(sizeof(char) * (strlen(argv[0]) + 20)); | |
char* dash_e; | |
strcat(dash_m, "-Mperl5i::cmd="); | |
strcat(dash_m, argv[0]); | |
perl_args[0] = (char *)perl_cmd; | |
perl_args[1] = dash_m; | |
i = 1; | |
pi = 2; | |
while ( i < argc ) { | |
if ( !strcmp( argv[i], "-e" )) { | |
dash_e = argv[i + 1]; | |
i = i + 2; | |
continue; | |
} | |
#if defined(WIN32) | |
/* Windows arguments aren't really a list but a single string, | |
* execv() fakes it, so we need to put the quotes back. | |
*/ | |
char* wrapped_arg = (char *)malloc( strlen(argv[i]) + 3 ); | |
sprintf(wrapped_arg, "\"%%s\"", argv[i]); | |
perl_args[pi] = wrapped_arg; | |
#else | |
perl_args[pi] = argv[i]; | |
#endif | |
i++; | |
pi++; | |
} | |
if ( dash_e ) { | |
FILE *prog = fopen( "xxxx.pl", "w"); | |
fprintf( prog, "%%s", dash_e ); | |
fclose( prog ); | |
perl_args[argc-1] = "xxxx.pl"; | |
perl_args[argc] = (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