The i3 FAQ has migrated to All content here is read-only.
Ask Your Question

Why can I send input to i3bar with bash script, but not with python?

asked 2015-07-13 13:28:38 +0000

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

As a test, I added this to my .i3/config:

bar {
    status_command i3status | ~/.i3/

with the script:


echo '{ "version": 1 }'
echo '['
echo '[]'
while :;
    echo ",[{\"name\":\"time\",\"full_text\":\"test\"}]"
    sleep 1

I see "test" on the i3bar. Nice. However, I want to use python for the real script, so I tried:

bar {
    status_command i3status | ~/.i3/


#!/usr/bin/env python
import time

print '{ "version": 1 }'
print '['
print '[]'
while True:
    print ',[{"name":"time","full_text":"test"}]'

but... no joy. Nothing on the i3bar. Running the scripts in terminal, the output looks the same. Even output to file and examined in hex, and it was the same. Is it some sort of problem with buffering? Even if I wait, nothing shows up on the bar. Tried running with "python ~/.i3/", still nothing. Am I missing something obvious? (That does happen to me a lot.) Thanks in advance!

edit retag flag offensive close merge delete


Yes, it's buffering. Try using "stdbuf -o 0 -e 0 python2.7 ~/.i3/" and you can see it works.

Airblader gravatar imageAirblader ( 2015-07-13 13:53:21 +0000 )edit

Thanks! Looks like you just beat me to it. Can't upvote, but props for the quick reply. There's a good discussion on the issue here (explains why it all looked fine in terminal):

will_82 gravatar imagewill_82 ( 2015-07-13 13:59:09 +0000 )edit

To be fair, stdbuf only meant to prove the theory, not to be a solution, so it wasn't an answer. Using "-u" is the right solution :)

Airblader gravatar imageAirblader ( 2015-07-13 16:13:37 +0000 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-07-13 13:53:21 +0000

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

Aghhh... just figured it out... it was a buffering problem. Needed to launch with

bar {
    status_command i3status | python -u ~/.i3/

This makes python send unbuffered output. Hope this helps someone else who's playing around with the i3bar and python. I've been pulling out my hair all day!

edit flag offensive delete link more

Question Tools


Asked: 2015-07-13 13:28:38 +0000

Seen: 212 times

Last updated: Jul 13