Ruby 指令正在關閉 tty echo

Ruby 指令正在關閉 tty echo

執行 Ruby 腳本後,幾乎 100% 的情況下,bash 命令列都會出現處於不活動狀態,而實際上它默默地接受我的擊鍵而不向我顯示它們。

透過多個作業系統更新,多個版本的 Ruby 都發生過這種情況;目前,我在 OS X 10.9.2 上執行 v1.9.2p29。reset解決問題;clear等人不這樣做。

下面的“現在你不”等是看不見的命令的輸出echo

$ echo Now you see my typing...
Now you see my typing...

$ bundle exec jekyll build
...
done.

$ This is the output of an unseen echo command

$ About to run "reset"

$ echo And we''re back.
And we're back.

stty -a工作正常時的輸出:

speed 9600 baud; 57 rows; 187 columns;
lflags: icanon isig -iexten echo echoe echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
    -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff -ixany imaxbel iutf8
    -ignbrk brkint -inpck ignpar -parmrk
oflags: opost onlcr oxtabs onocr onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = <undef>; eof = ^D; eol = <undef>;
    eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
    min = 1; quit = ^\; reprint = ^R; start = ^Q; status = <undef>;
    stop = ^S; susp = ^Z; time = 0; werase = ^W;

stty -a當事情不是時的輸出:

speed 9600 baud; 57 rows; 187 columns;
lflags: -icanon isig -iexten -echo echoe -echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
    -extproc
iflags: -istrip icrnl inlcr -igncr ixon -ixoff -ixany imaxbel iutf8
    -ignbrk brkint -inpck ignpar -parmrk
oflags: opost onlcr oxtabs onocr onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = <undef>; eof = <undef>; eol = <undef>;
    eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U;
    lnext = <undef>; min = 1; quit = ^\; reprint = <undef>;
    start = ^Q; status = <undef>; stop = ^S; susp = ^Z; time = 0;
    werase = <undef>;

我特別注意到,在 中lflagsecho已經變成了-echo

不確定是什麼原因造成的,或者我應該檢查哪些其他設定/診斷。

答案1

當您在提示中鍵入以下內容:

$ And now you don't.
> 

這將觸發命令列繼續。您顯然沒有在 OSX 上設定輔助提示(我猜是提示的事情),但您的問題是因為您正在使用該特定字串「$ And now you don't.`」。

當你輸入以下內容:

$ echo And we''re back.
And were back.

你正在關閉延續。嘗試使用不同的字串來查看是否存在相同的問題。

筆記:最根本的問題是你對'....'.

答案2

echo終端驅動程式設定中的設定指定終端驅動程式是否應該迴音返回您輸入的字元。類似vi現代 shell 的應用程式在他們的提示下不要使用它,他們也不使用終端規範模式,他們確實處理每個按鍵並且迴音您透過寫入終端設備自行輸入的內容。

但是,readline 和任何使用它的應用程序,例如bashgdb也停用他們的 迴音當它們偵測到終端echo已停用時,其他 shell 會喜歡zshtcsh不喜歡。

請注意,echo請始終在(或任何具有自己的行編輯器的現代 shell)shell 提示字元下停用它bash,因為 readline 會進行自己的回顯。bash/readline在每次提示之前保存終端設置,並將其設置為實現其行編輯器(包括禁用echo)所需的設置,並在運行命令之前將其重置為保存的值。

所以輸出stty -a就是已儲存的配置。並且bash/readline (但不是其他 shell)在echo禁用時禁用自己的回顯在已儲存的配置中

您可以透過發出以下命令來獲得與所看到的相同的行為:

stty -echo

應用程式通常在發出密碼提示時會停用終端回顯,或者像上面的情況一樣vibash以實現自己的文字編輯(然後它們不使用終端規範模式),並在退出時恢復設定。

您的情況的另一個區別是它icanon已被停用,這表明我們更有可能出現第二種情況。

您的 ruby​​ 腳本可能會啟動一個無法正確重置終端設定的視覺應用程式。如果該應用程式被不可捕獲的訊號(如 SIGKILL)終止,或者它仍在運行或掛起,則可能會發生這種情況。

若要恢復終端設置,您可以執行 astty sanereset。您可能需要檢查是否沒有進程仍在運行,以及該腳本運行的應用程式以及其行為不當的原因。

相關內容