[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: AW: Questions to bash "read" builtin functionality
From: |
Fiedler Roman |
Subject: |
AW: AW: Questions to bash "read" builtin functionality |
Date: |
Mon, 17 Dec 2012 14:12:30 +0000 |
> Von: Chet Ramey [mailto:chet.ramey@case.edu]
> Gesendet: Montag, 17. Dezember 2012 15:10
>
> On 12/17/12 3:34 AM, Fiedler Roman wrote:
> > That is strange: If I understand correctly, following script combined with
> > the
> one from first mail should still fail, but with different error. But it fails
> in a way
> similar to discarding partial input, not saving it. Could it be, that
> Ubuntu-bash
> works differently? Output on my side is:
> >
> > Script:
> >
> > #!/bin/bash
> > line=""
> > while true; do
> > read -t 1 line
> > status="$?"
> > if [ "${status}" != "0" ]; then
> > echo "Read status ${status}, value \"${line}\"" >&2
> > continue
> > fi
> > if [ "${line}" != "Status: OK" ]; then
> > echo "FAILED READ: \"${line}\"" >&2
> > exit 1
> > fi
> > done
> >
> > # ./FragmentedSend.py | ./BashReadTest
>
> What is FragmentedSend.py? If I can use the same scripts you are, I can
> try to reproduce it.
Sure, it was in the first mail of this thread:
base64 -d <<BASE64-EOF | tar -xj
QlpoOTFBWSZTWX5lCW0AAOl/xMwQAEB97f//NzycDn/v3uogAAAAgAhAAb1qpgGonpE9TagADQNN
NAAAAaD1AAEomkyGpPKaADQGnqANNPUMmgABoDjJk00wmRkDAjE0YIwg0aYABBJIpphCZiaTNT0h
o0AAAAaaAabU+Cv9dQPcQuSSaABIwQUkQNiTyBFsTAgcG2p0dIEciFV9EZfOok7RyV36nYqnFKSJ
QMO4OAgwMtnhGwTmvZXHNLdCTPwVBN6uopct/CzRFdFSwWj8XJd8plU/gyNLrSlHLzYfHU7wYsAp
zwbepqoV2GJYtNmAVZ1EYAEvzvgNCONxvrT0i4t65SLP1OkisWrcVnuxthOxKiZ5AktJbG2PmccG
IoiA7Mok66IR2eEH5BgUD4BlrvrZmvBaQNmJU3IiUZIPgVFrrcVLRKQTROURx8e14EY40h2oT1c6
APc4kqdy25cqSZh5XelCN0X5EsQUUNkJV9UdtBmLxK8I7iZl/LQ7OQl5PL4YiYMZY04JEXVctElZ
UilWStgdgM7PGQFCLDzmzYbdtnwEQMNC6ai+hyc0swZgkIgj1g05JTBy2CK9O6q+aC4GxU7Q2Uk0
qm1nbfmL0VDEEhOxVhDKbSUgKybpZgyBGTMPaEdGTlNZPC0soGO61Y8pBB/i7kinChIPzKEtoA==
BASE64-EOF
(export TMOUT=1; ./FragmentedSend.py | ./BashReadTest)
In plain:
#!/usr/bin/python
import os
import random
import sys
import time
sendDataBlock='Status: OK\n'
nextSendData=sendDataBlock
while True:
time.sleep(random.randint(980,1020)/1000)
sendLength=random.randint(1, 10)
while len(nextSendData) < sendLength:
nextSendData=nextSendData+sendDataBlock+sendDataBlock+sendDataBlock
os.write(1, nextSendData[0:sendLength])
nextSendData=nextSendData[sendLength:]