-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
fatal() | ||
{ | ||
printf '%s\n' "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
if ! which sexpect >& /dev/null; then | ||
fatal 'sexpect not found in your $PATH' | ||
fi | ||
|
||
export SEXPECT_SOCKFILE=/tmp/sexpect-$$.sock | ||
|
||
ps1re='bash-[0-9.]+[$#] $' | ||
sexpect spawn -idle 10 bash --norc | ||
if ! sexpect expect -t 5 -re "$ps1re"; then | ||
fatal "timed out waiting for the shell prompt" | ||
fi | ||
|
||
commands=( | ||
'echo hello world' | ||
'date' | ||
'echo "oN wnii tnrecaitevm do e..." | sed '\'s/'\(.\)\(.\)/\2\1/g'\' | ||
) | ||
for cmd in "${commands[@]}"; do | ||
sexpect send -cr "$cmd" | ||
sexpect expect -re "$ps1re" | ||
done | ||
|
||
sexpect interact -c -sub "([\r\n]+)?($ps1re)::(1)\e[1;35m(2)\e[m" |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
fatal() | ||
{ | ||
printf '%s\n' "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
if ! which sexpect >& /dev/null; then | ||
fatal 'sexpect not found in your $PATH' | ||
fi | ||
|
||
export SEXPECT_SOCKFILE=/tmp/sexpect-$$.sock | ||
|
||
sexpect spawn -idle 10 python3 | ||
if ! sexpect expect -t 5 ">>> "; then | ||
fatal "timed out waiting for the '>>> ' prompt" | ||
fi | ||
|
||
commands=( | ||
'from pprint import pprint as pp' | ||
'import json' | ||
'import os' | ||
'import random' | ||
'import re' | ||
'import sys' | ||
'import time' | ||
'print(re.sub("(.)(.)", r"\2\1", "oN wnii tnrecaitevm do e...") )' | ||
) | ||
for cmd in "${commands[@]}"; do | ||
sexpect send -cr "$cmd" | ||
sexpect expect ">>> " | ||
done | ||
|
||
sexpect interact -c -sub '([\r\n]+)?(>>> )$::(1)\e[1;35m(2)\e[m' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
fatal() | ||
{ | ||
printf '%s\n' "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
if ! which sexpect >& /dev/null; then | ||
fatal 'sexpect not found in your $PATH' | ||
fi | ||
|
||
export SEXPECT_SOCKFILE=/tmp/sexpect-$$.sock | ||
|
||
ps1re='bash-[0-9.]+[$#] $' | ||
sexpect spawn -idle 10 bash --norc | ||
if ! sexpect expect -t 5 -re "$ps1re"; then | ||
fatal "timed out waiting for the shell prompt" | ||
fi | ||
|
||
sexpect send -enter 'sum=0' | ||
sexpect expect -re "$ps1re" | ||
|
||
for ((i = 1; i <= 200; ++i)); do | ||
sexpect send -enter "(( sum += $i )); echo \$sum" | ||
if ! sexpect expect -t 5 -cstr -re "(5050)?[\r\n]+$ps1re"; then | ||
fatal "failed to wait for bash prompt or the final 5050" | ||
fi | ||
out=$( sexpect expect_out -index 1 ) | ||
if [[ $out == '5050' ]]; then | ||
break | ||
fi | ||
done | ||
|
||
if [[ $out == '5050' ]]; then | ||
sexpect send -enter ": cool we finally got 5050" | ||
else | ||
sexpect send -enter ": oops we did not get 5050" | ||
fi | ||
sexpect expect -re "$ps1re" | ||
|
||
sexpect send -enter exit | ||
sexpect wait |