Author Topic: CkSsh: How to get entire command output when the output includes null characters  (Read 88 times)

spino

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
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;
}



Chilkat

  • Administrator
  • Jr. Member
  • *****
  • Posts: 90
  • Karma: +4/-0
    • View Profile
You can call GetReceivedData instead.

spino

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Hi.

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

Best,