2

I have already tried a couple of things to get a live output from Popen. In my example, I try to get a output from steamcmd. The output comes, but it's very late and is in "blocks" not per line.

The current code looks so:

def call2(cmd, dir=None):
  if dir is None:
    dir = getScriptPath()

  p = sub.Popen(cmd, shell=True, stdout=sub.PIPE, bufsize=1, cwd=dir)
  for line in iter(p.stdout.readline, b''):
    print(line),
  p.stdout.close()
  p.wait()

utils.call2("./steamcmd.sh +login anonymous +force_install_dir %s +app_update 376030 +quite" % dir, main.p_steam)

I tried another piece of code but it has the same problem. Seems that this is a specific steamcmd issue but when I call that over the terminal manually it's having a direct output.

garg10may
  • 5,794
  • 11
  • 50
  • 91
Thee Cherry
  • 111
  • 10
  • are you making a html request or where is the data coming from? – Padraic Cunningham Oct 04 '15 at 10:25
  • no, there is no html request, its a shell script and I call it with Popen ... – Thee Cherry Oct 04 '15 at 10:49
  • 1. It's likely in blocked due to steamcmd buffering stdout. 2. You are going to have quite a few issues trying to use popen to stream steamcmd's stdout, because steamcmd's sub-processing *very* weird. If you do a bit of Googling, you'll see many others have the same problem. I have yet to find a resolution myself. – Liam Stanley Oct 04 '15 at 11:25
  • In addendum to above, one of the greater issues many have faced is that they can only manage to get the output of steamcmd, not what steamcmd executes (the actual server). Meaning things like player joins, chat, etc, people haven't been able to stream. – Liam Stanley Oct 04 '15 at 11:28
  • Ok see another have that problem too, but how can steamcmd.sh write it to the console instantly, but with a external call not. Don’t understand that. – Thee Cherry Oct 04 '15 at 12:14
  • [it is the block buffering issue](http://stackoverflow.com/a/12471855/4279) – jfs Oct 06 '15 at 05:01
  • unrelated: If you are on Python 2 then use: `print line,` instead of `print(line),` If you are on Python 3 then use `sys.stdout.buffer.write(line)`. – jfs Oct 06 '15 at 05:04
  • Hi! I'm currently facing the same issue but with strace instead of steamcmd. Seems that Popen has problems with buffered stdout, which yields the following options: Either flush stdout manually or edit the sourcecode of the program to an unbuffered output. – Druckermann Feb 09 '19 at 20:44

0 Answers0