有沒有辦法利用內置語音系統通知的命令leave和命令(MacOS)?say
我可以echo hello | say在命令列上做。
leave輸出一旦出現Time to leave!,該輸出如何通過管道傳輸?say
當我發出這個命令時,它只是掛起。(不創建請假流程)
# one minute from now
leave 0001
Alarm set for Fri Jun 3 15:55:05 CEST 2022. (pid 37692)
pgrep leave
37692
# triggers: Time to leave!
# one minute from now piped to say
# this one is just hanging there.... (no leave process created)
leave 0001 | say
男人離開
LEAVE(1) BSD General Commands Manual LEAVE(1)
NAME
leave -- remind you when you have to leave
SYNOPSIS
leave [[ ]hhmm]
DESCRIPTION
The leave utility waits until the specified time, then reminds you that you have to leave. You are reminded 5 minutes and 1 minute before the actual time, at
the time, and every minute thereafter. When you log off, leave exits just before it would have printed the next message.
The following options are available:
hhmm The time of day is in the form hhmm where hh is a time in hours (on a 12 or 24 hour clock), and mm are minutes. All times are converted to a 12 hour
clock, and assumed to be in the next 12 hours.
If the time is preceded by ` ', the alarm will go off in hours and minutes from the current time.
If no argument is given, leave prompts with "When do you have to leave?". A reply of newline causes leave to exit, otherwise the reply is assumed to be a
time. This form is suitable for inclusion in a .login or .profile.
To get rid of leave you should either log off or use `kill -s KILL' giving its process id.
SEE ALSO
calendar(1)
HISTORY
The leave command appeared in 3.0BSD.
BSD April 28, 1995 BSD
謝謝!
uj5u.com熱心網友回復:
聽起來像是leave每天寫一行輸出。如果say嘗試一次讀取所有標準輸入(或以其他方式執行任何型別的讀取,而不是一次一個字符在第一個換行處停止),則緩沖區永遠不會足夠滿以使其讀取在合理的時間內完成。
內置的 bashread執行這些(低效)一次一個字符的讀取,因此能夠更適當地從管道獲取內容(只要leave覆寫 libc 的默認緩沖行為,即從行緩沖切換到完全-當輸出不直接到 TTY 時緩沖;但如果它不這樣做,那是你應該向作業系統供應商報告的錯誤)。
say要為來自的每一行輸出運行一個新副本leave:
leave | while IFS= read -r line; do say <<<"$line"; done
要等到leave有一些輸出,只運行say一次,然后退出:
leave | { IFS= read -r line; say <<<"$line"; }
如果您愿意,所有這些都可以放在后臺。例如:
{ leave | { IFS= read -r line; say <<<"$line"; }
} </dev/null >leave-say.log 2>&1 & disown -h "$!"
...將相當于在后臺運行上述代碼nohup,將任何錯誤寫入leave-say.log而不是nohup.out.
uj5u.com熱心網友回復:
所做的是leave派生一個后臺行程,該行程在 STDOUT 上提供留言。完成分叉后,子行程從其父行程繼承 STDOUT。當父行程死亡時,子行程使管道中下一個行程的 STDIN 保持打開狀態。所以,
leave 0002 | sed 's/o/OOOO/g'
似乎掛起,直到子行程被殺死。
正確的解決方案是將管道的其余部分設定為背景:
leave 0002 | sed 's/o/OOOO/g' &
然后產生:
Just OOOOne mOOOOre minute!
Time tOOOO leave!
或者,在您的情況下:
leave 0002 |say &
殺死子行程將停止say“掛起”。孩子的 PID 在訊息中給出Alarm set for xx.xx. (pid 3311636)。您可以通過從另一個視窗殺死孩子來驗證這一點。
不是這樣的,如果你不離開,子行程不會死,而是會時不時的嘮叨。這意味著say將“
- 說“為pid設定警報(來自父級的輸出)
- 掛一會等待輸入
- 說“再等一分鐘!” (孩子的輸出)
- 再掛一分鐘
- 說“是時候離開了”(孩子的輸出)
- 再掛一分鐘
- 說“是時候離開了”(孩子的輸出)
(最后兩行重復,直到孩子被殺)
這也與 Macos 聯機幫助頁的say狀態一致:
如果輸入是 TTY,或者沒有指定文本,輸入的輸入文本將逐行朗讀
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/486239.html
