windows executable calling python script

Andrea Crotti andrea.crotti.0 at gmail.com
Mon Feb 27 10:05:22 EST 2012


On 02/27/2012 02:21 PM, Andrea Crotti wrote:
>
> At the moment I ended up with something like this:
>
> #include <stdarg.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
>
> // the function takes as arguments only the python interpreter full path
> int main(int argc, char *argv[])
> {
>   if (argc < 2) {
>     fprintf(stderr, "Usage = ./run <python_executable_path>");
>     exit(1);
>   }
>   /* TODO: make the path absolute? is it necessary? */
>   char *const to_run[1] = {"run.py"};
>   /* TODO: check if the path exists or not, and if it's executable */
>
>   execv(argv[1], to_run);
>   return 1;
> }
>
> which still doesn't work (I have to fix the execv) but when it will in 
> theory I will only need
> to tell NSIS to create a link to that executable passing as argument 
> the right python executable.
> After that it will run the run.py with in the local directory..
>
> Easier ways (without py2exe and similars?)?

For the record I think I found a solution, now the wrapper works:
int main(int argc, char *argv[])
{
   if (argc < 2) {
     fprintf(stderr, "Usage = ./run <python_executable_path>");
     exit(1);
   }
   /* TODO: make the path absolute? is it necessary? */
   char *const to_run[] = {"python", RUNNER, (char *) 0};
   execv(argv[1], to_run);
   return 1;
}

and I only need to tell NSIS to create a shortcut passing as argument 
the path to the python executable,
nice and simple..



More information about the Python-list mailing list