繁体   English   中英

使用popen()在C程序中执行ssh命令

[英]Executing ssh command in c program using popen()

当我尝试使用popen执行此操作时,它将返回此错误,但是当我在终端中运行此命令时,它将起作用!

 popen("ssh -n -f *.*.*.* 'sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3'", "r");

错误:

ssh_exchange_identification: Connection closed by remote host

我使用公钥和私钥在没有密码的情况下使用ssh,并且它们可以正常运行,因为此命令可以在终端中完美运行。

我将其更改为:

popen("ssh -n -f *.*.*.* `sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3`", "r");

它也返回错误。

错误:

fuse: bad mount point `/foo1/foo2/foo3': No such file or directory
Cannot fork into background without a command to execute.

我也尝试通过这种方式来隐藏内部的""\\" \\"但它挂起了!

将ssh替换为/usr/bin/ssh ,对其他命令(如sshfs)执行相同的操作。 指定命令的完整路径, /usr/sbin/foo或任何情况。 popen不一定使用您在命令行中具有的相同shell来执行命令。 检查您的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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