clarkwang/sexpect

How to determine the moment when spawned process requests stdin?

ivakyb opened this issue ยท 3 comments

Hi. Nice work ๐Ÿ‘.

I am looking for a way to colorize bash --verbose output. In other words my task is to execute a bash script highlighting every command before execution. During hours I looked for a solution but nothing worked as expected. Expected is:

$ command  # highlighted
out line 1
out line 2
$ multi-
  line-
  command2   # highlighted
out2
$ cmd3  # highlighted
...

Currently I think the best solution would be is to run background bash process and send commands to it when it is ready to read them. Parent script will read script to execute line by line and write colorized line to stderr, then send them to spawned sub-bash when it is wait for new input. This is required to do not mix outputs.

So the question

How to determine the moment when spawned process requests stdin with sexpect?

see my question on SO https://stackoverflow.com/questions/52708607/how-to-get-know-if-a-process-is-waiting-on-stdin

Already answered at SO.

Answered, but the answer is not sufficient. Bash is not able to solve the problem.

Answered, but the answer is not sufficient. Bash is not able to solve the problem.

I don't know a way to do that. For a FD, a process can check if it's readable or writable with select(2). But even the kernel tells the process that there are data available for read(2) the process can still choose not to read.