私はPythonコマンドラインプログラムを書いています。
エントリ ポイントとして機能するメインの Python スクリプト ファイルがあります。ユーザーがこのスクリプトを実行すると、いくつかの外部 Python スクリプト ファイルが実行されます。外部 Python スクリプト ファイルは、他の外部 Python スクリプト ファイルを実行することもできます。外部ファイルの数は可変です。
Python スクリプトは、以下を使用して外部 Python スクリプトを実行します。
p = subprocess.Popen(args)
or
p = subprocess.call(args)
ターミナル ウィンドウでメインの Python スクリプトを実行すると、実行中の画面にリアルタイムのログ メッセージが出力されます。ここで、メインの Python スクリプトによって呼び出されたすべての外部 Python スクリプトからすべてのログ メッセージを取得し、それを同じターミナル ウィンドウ (メイン スクリプトの実行に使用するターミナル ウィンドウ) に出力したいと考えています。
たとえば、以下はスクリプト実行のシーケンスです。
1.Main-script
|
2.Layer-1-script-1
|
3.Layer-2-script-1
|
4.Layer-2-script-2
|
5.Layer-1-script-2
|
6.Layer-1-script-3
|
7.Main-script(continued)
ターミナル ウィンドウでメイン スクリプトを実行すると、以下のようにターミナル ウィンドウでリアルタイムのログ メッセージを取得できますか?
[time-hh-mm-ss][log message from main script]Script is running..
[time-hh-mm-ss][log message from main script]Calling script layer-1-script-1..
[time-hh-mm-ss][log message from layer-1-script-1]Script is running..
[time-hh-mm-ss][log message from layer-1-script-1]Calling script layer-2-script-1..
[time-hh-mm-ss][log message from layer-2-script-1]Script is running..
[time-hh-mm-ss][log message from layer-2-script-1]Calling script layer-2-script-2..
[time-hh-mm-ss][log message from layer-2-script-2]Script is running..
[time-hh-mm-ss][log message from layer-2-script-2]Calling script layer-1-script-2..
[time-hh-mm-ss][log message from layer-1-script-2]Script is running..
[time-hh-mm-ss][log message from layer-1-script-2]Calling script layer-1-script-3..
[time-hh-mm-ss][log message from layer-2-script-3]Script is running..
[time-hh-mm-ss][log message from main script]Back to main script. Script is running..
real time log messages
端末ウィンドウで上記のようなものを取得できる可能性はありますか?