数行のプロセス出力をファイルにコピーします。

数行のプロセス出力をファイルにコピーします。

Qtアプリケーションのxinput-calibrator出力をtemp.txtファイルにコピーしたいと思います。

マイアプリケーションでQProcessを起動します。

このコマンドを使用すると、テキストxinput_calibrator | tee log.txt全体をコピーできますが、出力の数行だけをファイルに保存できます。

以下は出力ですxinput_calibrator

Warning: multiple calibratable devices found, calibrating last one (VirtualBox mouse integration)
use --device to select another one.
Calibrating EVDEV driver for "VirtualBox mouse integration" id=12
    current calibration values (from XInput): min_x=4, max_x=65512 and min_y=-52, max_y=65816

Doing dynamic recalibration:
    Setting new calibration data: 66, 65483, -125, 65584


--> Making the calibration permanent <--
  copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'
Section "InputClass"
    Identifier  "calibration"
    MatchProduct    "VirtualBox mouse integration"
    Option  "Calibration"   "66 65483 -125 65584"
EndSection

最後の5行をtemp.txtファイルにコピーします。

ベストアンサー1

@skwllspが述べたように、あなたの質問は大丈夫ですxinput_calibrator | tail -n 5 | tee log.txt。しかし、これを達成したい理由を尋ねてもいいですかtee

このteeユーティリティは、標準入力を標準出力にコピーしてゼロ個以上のファイルをコピーします。出力はバッファリングされません。

目的teeは、出力をファイルに書き込むことです。そしてパイプラインに次のコマンドを実行し続けます。

出力をファイルに送信するには、または>を使用して実行できます>>

xinput_calibrator | tail -n 5 > log.txt

log.txt存在しない場合は生成されます。null に切り捨てます。すでに存在する場合、出力はファイルに書き込まれます。

xinput_calibrator | tail -n 5 >> log.txt

古いデータが削除されないようにファイルに追加されます。 (ファイルがない場合は新しく作成します。)


追加資料:

おすすめ記事