]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // mock-program.cpp |
2 | // | |
3 | // Copyright (c) 2017 Steven Watanabe | |
4 | // | |
5 | // Distributed under the Boost Software License Version 1.0. (See | |
1e59de90 TL |
6 | // accompanying file LICENSE.txt or copy at |
7 | // https://www.bfgroup.xyz/b2/LICENSE.txt) | |
11fdf7f2 TL |
8 | |
9 | // This program does nothing except to exec a python script | |
10 | ||
11 | #include <vector> | |
12 | #include <iostream> | |
13 | #include <stdio.h> | |
14 | #include "config.h" | |
15 | ||
16 | #if defined(_WIN32) | |
17 | #include <process.h> | |
18 | #define execv _execv | |
19 | #else | |
20 | #include <unistd.h> | |
21 | #endif | |
22 | ||
23 | #ifndef PY_SCRIPT | |
24 | #error PY_SCRIPT must be defined to the absolute path to the script to run | |
25 | #endif | |
26 | ||
27 | #ifndef PYTHON_CMD | |
28 | #error PYTHON_CMD must be defined to the absolute path to the python interpreter | |
29 | #endif | |
30 | ||
31 | int main(int argc, char ** argv) | |
32 | { | |
33 | std::vector<char *> args; | |
34 | char python_cmd[] = PYTHON_CMD; | |
35 | char script[] = PY_SCRIPT; | |
36 | args.push_back(python_cmd); | |
37 | args.push_back(script); | |
38 | args.insert(args.end(), argv + 1, argv + argc); | |
39 | args.push_back(NULL); | |
40 | execv(python_cmd, &args[0]); | |
41 | perror("exec"); | |
42 | } |