Archived Forum Post

Index of archived forum posts

Question:

How to run compiled program using chilkat

Jul 04 '17 at 12:08

My aim is to make "cd /mydirpath" and run my program which was compiled before: "./a.out" Here is how I'm trying to make it:

const char *cmd1 = "cd /home/machinekit/projects";

char *cmd2 = "./a.out";

success = ssh.SendReqExec(channelNum, cmd1);    if (success != true) {      std::cout << ssh.lastErrorText() << "\r\n";         return;     }

    success = ssh.SendReqExec(channelNum, cmd2);    if (success != true) {      std::cout << ssh.lastErrorText() << "\r\n";         return;     }

The first command didn't return an error though the second one gives:

ChilkatLog: SendReqExec: DllDate: May 25 2017 ChilkatVersion: 9.5.0.68 UnlockPrefix: Anything for 30-day trial Architecture: Little Endian; 64-bit Language: Visual C++ 2017 / x64 VerboseLogging: 0 sendReqExec: command: a.out reqExecCharset: ANSI channel: 100 commandQP: a.out Unexpected message type received in response to exec request. messageType: 96 --sendReqExec Failed. --SendReqExec --ChilkatLog


Answer

Each command sent in SendReqExec is independent of others. (they are idempotent)

To accomplish what you want, you should make a single call to SendReqExec with a command that is a sequence of multiple commands.

See https://stackoverflow.com/questions/13077241/execute-combine-multiple-linux-commands-in-one-line

For example:

success = ssh.SendReqExec("cd /home/machinekit/projects && ./a.out");