diff --git a/cpp/scsiexec/scsiexec_core.cpp b/cpp/scsiexec/scsiexec_core.cpp index 9a50148b..86809b6d 100644 --- a/cpp/scsiexec/scsiexec_core.cpp +++ b/cpp/scsiexec/scsiexec_core.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace std; using namespace filesystem; @@ -135,14 +136,6 @@ void ScsiExec::ParseArguments(span args) } } - if (shut_down) { - return; - } - - if (input_filename.empty()) { - throw parser_exception("Missing input filename"); - } - if (target_id == -1) { throw parser_exception("Missing target ID"); } @@ -150,6 +143,14 @@ void ScsiExec::ParseArguments(span args) if (target_lun == -1) { target_lun = 0; } + + if (shut_down) { + return; + } + + if (input_filename.empty()) { + throw parser_exception("Missing input filename"); + } } int ScsiExec::run(span args, bool in_process) @@ -218,7 +219,25 @@ int ScsiExec::run(span args, bool in_process) return EXIT_SUCCESS; } - // TODO File output + if (binary) { + ofstream out(output_filename, ios::binary); + if (out.fail()) { + cerr << "Error: " << "Can't open binary protobuf output file '" << output_filename << "'" << endl; + } + + const string data = result.SerializeAsString(); + out.write(data.data(), data.size()); + } + else { + ofstream out(output_filename); + if (out.fail()) { + cerr << "Error: " << "Can't open JSON protobuf output file '" << output_filename << "'" << endl; + } + + string json; + MessageToJsonString(result, &json); + out << json << '\n'; + } CleanUp();