View script output over ssh in real time

294

Use the -u flag to python:

cat printdelay.py | ssh user@host python -u

The behavior you're seeing is because, when writing to stdout when stdout is not an interactive device such as a tty or pty, the printf family of functions flush the buffer less frequently. There's not a whole lot you can do about that except give Python a pty, as you discovered. This will work:

scp printdelay.py user@host:/tmp/timedelay.py
ssh -t user@host python /tmp/timedelay.py

(If you just cat timedelay.py | ssh -tt user@host python, python will have a pty and it will flush the buffer more frequently, but you will have other issues, for instance your script will get printed to stdout due to the way that pty allocation works with ssh.)

You can also try using the coreutils command stdbuf.

Share:
294

Related videos on Youtube

Anton
Author by

Anton

Updated on September 18, 2022

Comments

  • Anton
    Anton almost 2 years

    I have simple tableview with custom cell that contains uibutton. After update to iOS 9 GM or 9.1 Beta 1(it doesn't matter) button on cell stopped to response on touch. I have also create IBAction method inside cell class and it's also doesn't work at all

    cell.username.setAttributedTitle(attrNameString, forState: .Normal)
    cell.username.tag = notify.likeObject.likedUserId.integerValue
    cell.username.addTarget(self, action: "showProfile:", forControlEvents: .TouchUpInside)
    
    • Shamas S
      Shamas S almost 9 years
      Edit title of your question. Current title should be in tags.
  • thrig
    thrig over 7 years
    Or with a suitable version python -u to unbuffer everything or use sys.stdout.flush calls as appropriate or print(flush=True) and of course the usual debate over which is the most pythonic of these multiple ways to do things.
  • SauceCode
    SauceCode over 7 years
    Thanks for the explanation. Perhaps you could move the mention of the '-u' flag to the top of the answer. It looks like the neatest solution to me.