mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-16 10:37:21 +02:00
util: Remove brittle and confusing sp::Popen(std::string)
This commit is contained in:
@@ -8,12 +8,13 @@
|
||||
|
||||
#include <tinyformat.h>
|
||||
#include <univalue.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||
#include <util/subprocess.h>
|
||||
#endif // ENABLE_EXTERNAL_SIGNER
|
||||
|
||||
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in)
|
||||
UniValue RunCommandParseJSON(const std::vector<std::string>& cmd_args, const std::string& str_std_in)
|
||||
{
|
||||
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||
namespace sp = subprocess;
|
||||
@@ -22,9 +23,9 @@ UniValue RunCommandParseJSON(const std::string& str_command, const std::string&
|
||||
std::istringstream stdout_stream;
|
||||
std::istringstream stderr_stream;
|
||||
|
||||
if (str_command.empty()) return UniValue::VNULL;
|
||||
if (cmd_args.empty()) return UniValue::VNULL;
|
||||
|
||||
auto c = sp::Popen(str_command, sp::input{sp::PIPE}, sp::output{sp::PIPE}, sp::error{sp::PIPE});
|
||||
auto c = sp::Popen(cmd_args, sp::input{sp::PIPE}, sp::output{sp::PIPE}, sp::error{sp::PIPE});
|
||||
if (!str_std_in.empty()) {
|
||||
c.send(str_std_in);
|
||||
}
|
||||
@@ -38,7 +39,7 @@ UniValue RunCommandParseJSON(const std::string& str_command, const std::string&
|
||||
std::getline(stderr_stream, error);
|
||||
|
||||
const int n_error = c.retcode();
|
||||
if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error, error));
|
||||
if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", util::Join(cmd_args, " "), n_error, error));
|
||||
if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result);
|
||||
|
||||
return result_json;
|
||||
|
||||
Reference in New Issue
Block a user