Realtime scp output with ruby
I have had an annoying problem recently with a shell script where it would not show the output of an scp command in realtime. Initially I was fighting with different methods of capturing output in realtime from a ruby script.
The solution to this which I went for is using IO.popen
eg.
However, this was only part of the solution. It wasnt working so I even tried implementing a solution in python.
To my surprise, all was quiet so had a check in the terminal and it would output fine. Hmmm.
After some time with mr google, I managed to track down the issue with scp itself. It runs the isatty() function to check and see if the command is being run in a shell. If it is not, then all is quiet! This means ruby, python et al do not get scp output.
The solution thanks to stack exchange was to send all output to a shell!
eg.
Hope this helps you if you are having a similar issue!