diff options
author | Yuchen Zeng <zyc@google.com> | 2016-07-07 14:13:35 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-07-07 16:42:32 -0700 |
commit | c68640f05cea2cf79bf2703d83da6b76fa6dc5e6 (patch) | |
tree | 0a54735a5c91ac017678c203caee66048e3fdcff /test/cpp | |
parent | 39070fe3a536819708aaa4422ea912b303cbe30f (diff) |
Read from stdin
Read from stdin if the request text and binary file are not provided
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/util/grpc_cli.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc index 7c8e2cdc63..fdb1a7c2a0 100644 --- a/test/cpp/util/grpc_cli.cc +++ b/test/cpp/util/grpc_cli.cc @@ -64,6 +64,7 @@ < output.bin > output.txt */ +#include <unistd.h> #include <fstream> #include <iostream> #include <sstream> @@ -146,7 +147,6 @@ int main(int argc, char** argv) { grpc::string serialized_request_proto; if (argc == 5) { - // TODO(yangg) read from stdin as well? request_text = argv[4]; } @@ -164,10 +164,15 @@ int main(int argc, char** argv) { grpc::CreateChannel(server_address, creds); if (request_text.empty() && FLAGS_input_binary_file.empty()) { - std::cout << "Missing input. Use text format input or " - << "--input_binary_file for serialized request" << std::endl; - return 1; - } else if (!request_text.empty()) { + if (isatty(STDIN_FILENO)) { + std::cout << "reading request message from stdin..." << std::endl; + } + std::stringstream input_stream; + input_stream << std::cin.rdbuf(); + request_text = input_stream.str(); + } + + if (!request_text.empty()) { if (!FLAGS_proto_file.empty()) { parser.reset(new grpc::testing::ProtoFileParser( FLAGS_proto_path, FLAGS_proto_file, method_name)); @@ -178,6 +183,12 @@ int main(int argc, char** argv) { if (parser->HasError()) { return 1; } + + if (!FLAGS_input_binary_file.empty()) { + std::cout + << "warning: request given in argv, ignoring --input_binary_file" + << std::endl; + } } if (parser) { @@ -226,7 +237,7 @@ int main(int argc, char** argv) { } } else { std::cout << "Rpc failed with status code " << s.error_code() - << " error message " << s.error_message() << std::endl; + << ", error message: " << s.error_message() << std::endl; } return 0; |