mirror of
https://github.com/google/cdc-file-transfer.git
synced 2026-09-13 01:10:44 +03:00
[RemoteUtil] Fix output from Windows SSH commands (#90)
Adds an ArchType argument to many RemoteUtil methods, which is used to replace -tt (forced pseudo-TTY allocation) by -T (no pseudo-TTY allocation). The -tt option adds tons of ANSI escape sequences to the output and makes it unparsable, even after removing the sequences, as some sequences like "delete the last X characters" are not honoured. An exception is BuildProcessStartInfoForSshPortForward, where replacing -tt by -T would make the port forwarding process exit immediately.
This commit is contained in:
+18
-6
@@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "common/arch_type.h"
|
||||
#include "common/process.h"
|
||||
|
||||
namespace cdc_ft {
|
||||
@@ -92,15 +93,24 @@ class RemoteUtil {
|
||||
|
||||
// Runs |remote_command| on the remote device. The command must be properly
|
||||
// escaped. |name| is the name of the command displayed in the logs.
|
||||
absl::Status Run(std::string remote_command, std::string name);
|
||||
// |remote_arch_type| is the arch type of the remote device. It determines
|
||||
// which type of pseudo console is used (-T on Windows, -tt on Linux). If the
|
||||
// wrong arch type is passed, output might be corrupted, but otherwise the
|
||||
// command will work.
|
||||
absl::Status Run(std::string remote_command, std::string name,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
// Same as Run(), but captures both stdout and stderr.
|
||||
// If |std_out| or |std_err| are nullptr, the output is not captured.
|
||||
// |remote_arch_type| is the arch type of the remote device, see Run().
|
||||
absl::Status RunWithCapture(std::string remote_command, std::string name,
|
||||
std::string* std_out, std::string* std_err);
|
||||
std::string* std_out, std::string* std_err,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
// Builds an SSH command that executes |remote_command| on the remote device.
|
||||
ProcessStartInfo BuildProcessStartInfoForSsh(std::string remote_command);
|
||||
// |remote_arch_type| is the arch type of the remote device, see Run().
|
||||
ProcessStartInfo BuildProcessStartInfoForSsh(std::string remote_command,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
// Builds an SSH command that runs SSH port forwarding to the remote device,
|
||||
// using the given |local_port| and |remote_port|. If |reverse| is true, sets
|
||||
@@ -112,9 +122,10 @@ class RemoteUtil {
|
||||
// Builds an SSH command that executes |remote_command| on the remote device,
|
||||
// using port forwarding with given |local_port| and |remote_port|. If
|
||||
// |reverse| is true, sets up reverse port forwarding.
|
||||
// |remote_arch_type| is the arch type of the remote device, see Run().
|
||||
ProcessStartInfo BuildProcessStartInfoForSshPortForwardAndCommand(
|
||||
int local_port, int remote_port, bool reverse,
|
||||
std::string remote_command);
|
||||
int local_port, int remote_port, bool reverse, std::string remote_command,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
// Returns whether output is suppressed.
|
||||
bool Quiet() const { return quiet_; }
|
||||
@@ -145,7 +156,8 @@ class RemoteUtil {
|
||||
private:
|
||||
// Common code for BuildProcessStartInfoForSsh*.
|
||||
ProcessStartInfo BuildProcessStartInfoForSshInternal(
|
||||
std::string forward_arg, std::string remote_command);
|
||||
std::string forward_arg, std::string remote_command,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
const int verbosity_;
|
||||
const bool quiet_;
|
||||
|
||||
Reference in New Issue
Block a user