Bash:ttyのechoコマンド

Bash:ttyのechoコマンド

次のようにコマンドを受け取り、操作を実行するPythonで書かれたサービスがあります.

    print("\nWelcome!\n")

    for line in sys.stdin:
        cmd=line.rstrip()
        if cmd == "ls" or cmd == "help":
            print("Available Commands:")

これでサービスが開始されたので、対応するsystemd単位ファイルは次のようになります。

[Service]
Environment=PYTHONUNBUFFERED=1
ExecStart=...service.py
WorkingDirectory=...

StandardOutput=tty
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty60
TTYReset=yes

したがって、サービスの入力と出力はに接続され、サービスが実行する操作を確認し、サービスと対話することがtty60できます。たとえば、conspy 60ここに次のように入力します。testhelp

test
Error: command 'test' not found.
Type 'help' for a list of available commands.

help
Avaliable Commands:
> status, fan1, fan2, fan3, fan4, wake, sleep, quit

Pythonは私が入力したものを受け取り、期待どおりに答えを提供することができました。

今、ttyインタラクティブプログラムのようなものを入力せずにどのようにコマンドを送信できますかconspy

疲れていますecho -e "ls\n" >> /dev/tty60。他の端末でconspyコマンドを表示できますが、Pythonはコマンドを処理しません。

help **---> sent via conspy**
Avaliable Commands:
> status, fan1, fan2, fan3, fan4, wake, sleep, quit
help **---> sent with "echo"**

ご覧のとおり、最後にhelp送信されたパスはecho処理されませんでした。

ありがとうございます。

ベストアンサー1

おすすめ記事