如何在命令中传递多个参数,以使用C/C 和SSH在远程Linux计算机上执行EXE

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

本文关键字:SSH Linux EXE 执行 计算机 命令 参数      更新时间:2023-10-16

我使用命令成功地在本地计算机上执行了我的EXE" ./excutable agr1 arg2 arg3 arg4"然后,它显示了参数计数的价值为5。但是,当我想从远程Linux计算机(System2)进行相同的操作,然后我使用QT Creator中的libssh打开了SSH频道,然后我确实以下内容:

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

然后执行的EXE,但显示为1。表示参数未正确传递。正确的方法是什么?

问题是QString格式,使用以下格式

qString str = qString("%1%2%3%4%5")。arg("/root/oferable"," arg1"," arg2"," arg2"," arg3"," arg3"," arg4"); p> rc = channel_request_exec(channel,str);

在在Google和Stackoverflow上进行了大量搜索之后(并且是变体),我发现了上述问题的答案,这并不是一个格式化错误。问题在于SSH本身。它不允许我们精确地指定命令。通过多个参数传递命令的正确方法如下:const char str [] =" "/root/oputable arg1 arg2 arg2 arg3 arg4 ";而且效果很好。

我在这里找到了答案:https://unix.stackexchange.com/q/80821https://unix.stackexchange.com/a/80838