from datetime import datetime
from jinja2.sandbox import SandboxedEnvironment
-tmpl = json.loads(sys.argv[1])
-vars_json = json.loads(sys.argv[2])
+merged_input = json.loads(sys.stdin.buffer.read().decode("utf-8"))
+tmpl = merged_input["tmpl"]
+vars_json = merged_input["vars"]
env = SandboxedEnvironment(
trim_blocks=True,
static void test_template_py(testing & t, const std::string & name, const std::string & tmpl, const json & vars, const std::string & expect) {
t.test(name, [&tmpl, &vars, &expect](testing & t) {
// Prepare arguments
- std::string tmpl_json = json(tmpl).dump();
- std::string vars_json = vars.dump();
+ json merged;
+ merged["tmpl"] = json(tmpl);
+ merged["vars"] = vars;
#ifdef _WIN32
const char * python_executable = "python.exe";
const char * python_executable = "python3";
#endif
- const char * command_line[] = {python_executable, "-c", py_script.c_str(), tmpl_json.c_str(), vars_json.c_str(), NULL};
+ const char * command_line[] = {python_executable, "-c", py_script.c_str(), NULL};
struct subprocess_s subprocess;
int options = subprocess_option_combined_stdout_stderr
t.assert_true("subprocess creation", false);
return;
}
+ FILE * p_stdin = subprocess_stdin(&subprocess);
+
+ // Write input
+ std::string input = merged.dump();
+ auto written = fwrite(input.c_str(), 1, input.size(), p_stdin);
+ if (written != input.size()) {
+ t.log("Failed to write complete input to subprocess stdin");
+ t.assert_true("subprocess stdin write", false);
+ subprocess_destroy(&subprocess);
+ return;
+ }
+ fflush(p_stdin);
+ fclose(p_stdin); // Close stdin to signal EOF to the Python process
+ subprocess.stdin_file = nullptr;
// Read output
std::string output;