diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp index 7b449ebedb2..685cd82a4a4 100644 --- a/gnucash/gnucash-commands.cpp +++ b/gnucash/gnucash-commands.cpp @@ -611,10 +611,11 @@ Gnucash::run_scripting (std::vector m_script_args, gnc_shutdown_cli (1); } - std::vector newArgv (m_script_args.size()); - auto to_c_str = [](std::string& s) { return (char*)s.c_str(); }; - std::transform (m_script_args.begin(), m_script_args.end(), newArgv.begin(), to_c_str); - // note the vector is valid as long as m_script_args's strings are not damaged! + std::vector newArgv (m_script_args.size() + 1); + newArgv.push_back ("gnucash-cli"); // because python strips argv[0] + std::transform (m_script_args.begin(), m_script_args.end(), std::back_inserter(newArgv), + [](const std::string& s) { return s.c_str(); }); + // note the vector is valid as long as m_script_args's strings are not damaged! gnc_prefs_init (); gnc_ui_util_init(); @@ -624,7 +625,7 @@ Gnucash::run_scripting (std::vector m_script_args, scripting_args args { m_script, m_language, m_interactive }; if (m_language == "guile") { - scm_boot_guile (newArgv.size(), newArgv.data(), run_guile_cli, &args); + scm_boot_guile (newArgv.size(), (char**)newArgv.data(), run_guile_cli, &args); return 0; // never reached... } @@ -634,7 +635,7 @@ Gnucash::run_scripting (std::vector m_script_args, PyConfig config; PyConfig_InitPythonConfig(&config); - PyStatus status = PyConfig_SetBytesArgv(&config, newArgv.size(), newArgv.data()); + PyStatus status = PyConfig_SetBytesArgv(&config, newArgv.size(), (char**)newArgv.data()); try { if (PyStatus_Exception(status))