简体   繁体   中英

How to pass multiple arguments in a command to execute an exe on remote linux machine using C/C++ and SSH

I have successfully executed my exe on local machine using command "./executable agr1 arg2 arg3 arg4" Then it shows value of argument count to 5. But when I wanted to do this same from a remote linux machine (system2) then I opened up SSH channel using libssh in QT creator then I did following:

  1. QString str = "/root/executable arg1 arg2 arg3 arg4";
  2. rc = channel_request_exec(channel, str);

Then the exe executed but it showed argument count to 1. Means arguments didn't passed correctly. What is the correct way of doing this ??

Problem is in QString format, use below format

QString str = QString("%1 %2 %3 %4 %5").arg("/root/executable", "arg1", "arg2", "arg3","arg4");

rc = channel_request_exec(channel, str);

After lots of search on Google and Stackoverflow ( and it's variant) I found answer to above problem and that was not exactly a formatting error. The problem is with SSH itself. It doesn't let us specify a command precisely. The correct way to pass a command with multiple arguments is as follows: Const char str[] = "\\"/root/executable arg1 arg2 arg3 arg4\\""; And it worked perfectly.

I found my answer here: https://unix.stackexchange.com/q/80821 https://unix.stackexchange.com/a/80838

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM