Bash command to re-emulate a keystroke on a procedure

nmap has this function - when you scan [#nmap -A -T4 localhost] and press "Enter" - it displays the status information "Timing: about 6.17% done",

Question. How can I make this press a few times without touching the keyboard in the bourne shell?

ps: just trying to find a workaround for an error in the php proc_open function when the stdout of the process returns only after the stdout pipe is closed, and php pty emulation does not work on fbsd.

The question is closed. The problem is solved using the "expect" utility

#!/usr/local/bin/expect

spawn /usr/local/bin/nmap -A -T4 -p 21-100 localhost
expect arting {sleep 3; send \r}
while {1} {
        expect eof {
            send_user "finished\n";
            exit;
        } "done;" {
            sleep 3;
            send \r;
            continue;
        }

}
+3
source share
3
+3

, " " , - "" .

yes ok | recalcitrant.php 

'ok' plus newline PHP. , . GNU Unix.

- , Tcl-based expect '

+1

: :

spawn /usr/local/bin/nmap -A -T4 -p 21-100 localhost
expect arting {sleep 3; send \r}
expect {
    "done;" {
        sleep 3
        send \r
        exp_continue
    }
    eof
}
puts "finished"

, sleep s? -regexp expect.

: exp_internal 1, , .

+1

Source: https://habr.com/ru/post/1734256/


All Articles