diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index a0e92871d..444588883 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -264,25 +264,27 @@ int ConsoleCommand::Run(const po::variables_map& vm, const std::vector(); else if (vm.count("file")) { - std::string fname = vm["file"].as(); + commandFileName = vm["file"].as(); try { - std::ifstream fp(fname.c_str()); + std::ifstream fp(commandFileName.CStr()); fp.exceptions(std::ifstream::failbit | std::ifstream::badbit); command = String(std::istreambuf_iterator(fp), std::istreambuf_iterator()); } catch (const std::exception&) { - std::cerr << "Could not read file '" << fname << "'." << std::endl; + std::cerr << "Could not read file '" << commandFileName << "'." << std::endl; return EXIT_FAILURE; } } - return RunScriptConsole(scriptFrame, addr, session, command, syntaxOnly); + return RunScriptConsole(scriptFrame, addr, session, command, commandFileName, syntaxOnly); } -int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& addr, const String& session, const String& commandOnce, bool syntaxOnly) +int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& addr, const String& session, const String& commandOnce, const String& commandOnceFileName, bool syntaxOnly) { std::map lines; int next_line = 1; @@ -329,7 +331,13 @@ int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& add } while (std::cin.good()) { - String fileName = "<" + Convert::ToString(next_line) + ">"; + String fileName; + + if (commandOnceFileName.IsEmpty()) + fileName = "<" + Convert::ToString(next_line) + ">"; + else + fileName = commandOnceFileName; + next_line++; bool continuation = false; @@ -448,7 +456,7 @@ incomplete: DebugInfo di = ex.GetDebugInfo(); - if (lines.find(di.Path) != lines.end()) { + if (commandOnceFileName.IsEmpty() && lines.find(di.Path) != lines.end()) { String text = lines[di.Path]; std::vector ulines; diff --git a/lib/cli/consolecommand.hpp b/lib/cli/consolecommand.hpp index 695a98cd5..4c7a5d3c2 100644 --- a/lib/cli/consolecommand.hpp +++ b/lib/cli/consolecommand.hpp @@ -47,7 +47,8 @@ public: virtual int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; static int RunScriptConsole(ScriptFrame& scriptFrame, const String& addr = String(), - const String& session = String(), const String& commandOnce = String(), bool syntaxOnly = false); + const String& session = String(), const String& commandOnce = String(), const String& commandOnceFileName = String(), + bool syntaxOnly = false); private: mutable boost::mutex m_Mutex;