1

Hi i am trying to create an ash script to read lines from stdin in a non blocking way.

In bash i can do something like this: read -t 0 && read line

But in ash on OpenWRT(LEDE version 17.01.16) i am unable to do this since on this version of OpenWRT read -t 0 is blocking :(

So how can i check if stdin has some data to read.

In particular i want to read a line from stdin if input is available otherwise just skip and will try later.

Is there any other possibile way to do this?

  • What process are you receiving from? – tink Apr 25 '21 at 19:44
  • @TheCatWasDrunk - Is `stty` available on that system? – Armali Apr 25 '21 at 19:45
  • 1
    @tink i am receiving from tcpdump and i am trying to count the number of packets received in about 100ms. tcpdump output is piped to my script. – TheCatWasDrunk Apr 25 '21 at 20:59
  • @Armali is that a command? If so no. – TheCatWasDrunk Apr 25 '21 at 21:00
  • Yes, [coreutils-stty](https://openwrt.org/packages/pkgdata/coreutils-stty); but we can forget that since _stdin_ is not a TTY. Would you rather install [package: bash](https://openwrt.org/packages/pkgdata/bash), which has 314kB? Otherwise, is a C compiler available, or a compiler or interpreter of another language? – Armali Apr 25 '21 at 22:56
  • @Armali the package you linked is for OpenWrt-19.07.0 while mine is version 17.01.16 and I don't know if it is possible to install it. For what regards the C compiler there is none. – TheCatWasDrunk Apr 26 '21 at 08:04
  • I'm afraid if there are no other shells (ksh?) or tools present or installable, I'm out of ideas. – Armali Apr 26 '21 at 08:28
  • 1
    @Armali there is nothing else. I guess I am asking something impossible anyway so don't panic :P – TheCatWasDrunk Apr 26 '21 at 08:50

0 Answers0