简体   繁体   English

SSH 用于运行远程二进制档

[英]SSH for running a remote binary stalls

I am configuring a vs-code extension to send a cross-compiled binary to a raspberry pi.我正在配置一个 vs-code 扩展以将交叉编译的二进制文件发送到树莓派。

Every step from compiling to copying the file runs fine.从编译到复制文件的每一步都运行良好。

ssh pi@123.123.123.123 "sudo mkdir /home/pi/remotePi/"; 
ssh pi@123.123.123.123 "sudo rm /home/pi/remotePi/blink_example";
ssh pi@123.123.123.123 "sudo chown pi /home/pi/remotePi/"; 
scp -l 8192 build/blink_example pi@123.123.123.123:/home/pi/remotePi/ && 
ssh pi@123.123.123.123 "echo "scp complete"" && 
ssh pi@123.123.123.123 "/home/pi/remotePi/blink_example"

Output: Output:

mkdir: cannot create directory ‘/home/pi/remotePi/’: File exists
blink_example                                                                                                                     100% 8692   277.3KB/s   00:00    
scp complete

But when I try to run the file through an SSH command, the command stalls.但是当我尝试通过 SSH 命令运行该文件时,该命令会停止。

ssh pi@123.123.123.123 "home/pi/remotePi/blink_example"

It will eventually run, but it can take around 10 minutes.它最终会运行,但可能需要大约 10 分钟。 If I ssh into the pi and run the binary through an actual terminal, it runs immediately.如果我将 ssh 放入 pi 并通过实际终端运行二进制文件,它会立即运行。

I have noticed that when it finally runs (using my extension), there are a lot of print statements (the test code just prints the read value from a pin).我注意到,当它最终运行时(使用我的扩展程序),有很多打印语句(测试代码只是打印来自 pin 的读取值)。 Does that mean it is running, but I'm maybe not getting the prints until there is enough to fill a packet?这是否意味着它正在运行,但我可能直到有足够的数据来填充数据包才得到打印?

So my question is, how can I run a binary on a remote machine and receive the terminal output in a timely manner?所以我的问题是,如何在远程机器上运行二进制文件并及时接收终端 output?


Edit编辑

I modified my program to not have any delays between print statements (essentially spamming stdout).我修改了我的程序,使打印语句之间没有任何延迟(本质上是垃圾邮件标准输出)。 This resulted in the ssh command ssh pi@123.123.123.123 "/home/pi/remotePi/blink_example" to return immediately and with all the prints.这导致 ssh 命令ssh pi@123.123.123.123 "/home/pi/remotePi/blink_example"立即返回所有打印。

This leads me to believe that there is a buffer that I need to fill (or limit the size of) before any terminal information is returned to the local device from the remote.这使我相信在任何终端信息从远程返回到本地设备之前,我需要填充(或限制其大小)缓冲区。

I figured out a solution, but it doesn't answer any of the questions about why spamming stdout will cause ssh to give a terminal output sooner.我想出了一个解决方案,但它没有回答任何关于为什么垃圾邮件标准输出会导致 ssh 更快地给终端 output 的问题。

In the original blink_example, I was using printf("pin 17: %d\n", digitalRead(17));在最初的 blink_example 中,我使用的是printf("pin 17: %d\n", digitalRead(17)); for displaying the value.用于显示值。

I converted the test application to c++ (not a terribly difficult task) and used std::cout << "pin 17: " << digitalRead(17) << std::endl;我将测试应用程序转换为 c++(不是一项非常困难的任务)并使用std::cout << "pin 17: " << digitalRead(17) << std::endl; . . Using this caused the terminal to give feedback right away.使用它会导致终端立即给出反馈。

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

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