@@ -1897,8 +1897,9 @@ import sys
18971897from datetime import datetime
18981898from jinja2.sandbox import SandboxedEnvironment
18991899
1900- tmpl = json.loads(sys.argv[1])
1901- vars_json = json.loads(sys.argv[2])
1900+ merged_input = json.loads(sys.stdin.buffer.read().decode("utf-8"))
1901+ tmpl = merged_input["tmpl"]
1902+ vars_json = merged_input["vars"]
19021903
19031904env = SandboxedEnvironment(
19041905 trim_blocks=True,
@@ -1921,16 +1922,17 @@ sys.stdout.buffer.write(result.encode())
19211922static void test_template_py (testing & t, const std::string & name, const std::string & tmpl, const json & vars, const std::string & expect) {
19221923 t.test (name, [&tmpl, &vars, &expect](testing & t) {
19231924 // Prepare arguments
1924- std::string tmpl_json = json (tmpl).dump ();
1925- std::string vars_json = vars.dump ();
1925+ json merged;
1926+ merged[" tmpl" ] = json (tmpl);
1927+ merged[" vars" ] = vars;
19261928
19271929#ifdef _WIN32
19281930 const char * python_executable = " python.exe" ;
19291931#else
19301932 const char * python_executable = " python3" ;
19311933#endif
19321934
1933- const char * command_line[] = {python_executable, " -c" , py_script.c_str (), tmpl_json. c_str (), vars_json. c_str (), NULL };
1935+ const char * command_line[] = {python_executable, " -c" , py_script.c_str (), NULL };
19341936
19351937 struct subprocess_s subprocess;
19361938 int options = subprocess_option_combined_stdout_stderr
@@ -1944,6 +1946,20 @@ static void test_template_py(testing & t, const std::string & name, const std::s
19441946 t.assert_true (" subprocess creation" , false );
19451947 return ;
19461948 }
1949+ FILE * p_stdin = subprocess_stdin (&subprocess);
1950+
1951+ // Write input
1952+ std::string input = merged.dump ();
1953+ auto written = fwrite (input.c_str (), 1 , input.size (), p_stdin);
1954+ if (written != input.size ()) {
1955+ t.log (" Failed to write complete input to subprocess stdin" );
1956+ t.assert_true (" subprocess stdin write" , false );
1957+ subprocess_destroy (&subprocess);
1958+ return ;
1959+ }
1960+ fflush (p_stdin);
1961+ fclose (p_stdin); // Close stdin to signal EOF to the Python process
1962+ subprocess.stdin_file = nullptr ;
19471963
19481964 // Read output
19491965 std::string output;
0 commit comments