你猛砸應用程序需要pseudo terminal才能正常運行。它需要屏幕大小和光標位置,但是如果使用管道輸入(<
或|
)運行它,則不會創建僞終端。
虛擬終端在Unix上被日常應用程序創建,如ssh
,xterm
和screen
。 (Expect會爲應用程序創建一個僞終端,並允許您運行自動測試。它支持測試生成與autoexpect
,並存在紙張上using Expect for terminal screen-scraping。)
如果您不能使用期望,你可以嘗試使用screen
用於自動化終端I/O:
# Create a detached screen
screen -S screenname -d -m -s ./my_app
# Send input to it
screen -S screenname -p windownum -X eval \
"register . \"arbitrary\ntext, newlines and control chars\n\"" paste
# Wait for the application to process the input
sleep 0.1s
# Dump the screen to a file
screen -S screenname -p windownum -X hardcopy ./screen_dump
# Check the dump
grep 'Login successful' ./screen_dump || exit 1
# Rinse and repeat
# Close the screen
screen -S screenname -X quit
你可以用xdotool來做到這一點。看到這個答案:http://stackoverflow.com/questions/7312527/sending-a-keypress-to-an-application/7312865#7312865 – holygeek
系統上沒有X,它只有一個控制檯應用程序 – user368507
[這是一種方法](http://stackoverflow.com/questions/7370538/ask-a-running-bash-interactive-to-run-a-command-from-outside/7370822#7370822) –