Chilkat Forum

General => General Discussion => Topic started by: spino on April 06, 2018, 05:00:39 PM

Title: CkSsh: How to get entire command output when the output includes null characters
Post by: spino on April 06, 2018, 05:00:39 PM
Hi,

I'm running a command that outputs null characters (cat /proc/$some_ip/cmdline). The issue is that when I get the string using getReceivedText, the string is chopped or incomplete (because c/c++ strings are finished using the null character).

So, doesn't Chilkat offers a way to get the entire output?

In the reproducible bellow, I'm expecting:
"Step 1"
"Hi"
"Step 2"

But only get "Step 1"

#include <CkSsh.h>
#include <stdio.h>

int main()
{
  CkSsh ssh;

  bool status = ssh.UnlockComponent(...);
  if (!status) {
    printf("%s\n", ssh.lastErrorText());
    return -1;
  }

  status = ssh.Connect("host", 22);
  if (!status) {
    printf("%s\n", ssh.lastErrorText());
    return -1;
  }

  status = ssh.AuthenticatePw("user", "pass");
  if (!status) {
    printf("%s\n", ssh.lastErrorText());
    return -1;
  }

  const char* cmd = "echo 'Step 1'; echo -e '\\0 Hi'; echo 'Step 2'";
  printf("%s\n", cmd);
  const char* stdOut = ssh.quickCommand(cmd, "unicode");
  if (!ssh.get_LastMethodSuccess()) {
    printf("%s\n", ssh.lastErrorText());
    return -1;
  }

  printf("stdOut: '%s'\n", stdOut);

  ssh.Disconnect();

  return 0;
}


Title: Re: CkSsh: How to get entire command output when the output includes null characters
Post by: Chilkat on April 07, 2018, 12:09:11 PM
You can call GetReceivedData instead.
Title: Re: CkSsh: How to get entire command output when the output includes null characters
Post by: spino on April 12, 2018, 10:48:19 AM
Hi.

Thanks for the suggestion. I try using GetReceivedData and it works!

Best,