4

How can I write data to stdout instead of writing file?

I'm using GPG and want to print encrypted text to stdout, without saving files.

However, with gpg command, encrypted text is written to file in ordinary way:

$> gpg --recipient someone@example.com --armor --output encrypted.txt --encrypt example.pdf

(With above command, encrypted file is saved in encrypted.txt)

What I want to do is like following:

$> gpg --recipient someone@example.com --armor --output <STDOUT> --encrypt example.pdf

and encrypted messages are shown in console.

I don't want to save hard disk to avoid loss of performance.

4

3 に答える 3

6

通常、「-」を使用して stdout を指定しますが、すべてのコマンドがこれを受け入れるわけではありません。

例えば:

tar -cvzf - foo/ ¦ split -b 50k foobar_

「tar-file」を標準出力にパイプし、分割して「foobar_<123...>」に保存します。

于 2012-06-26T04:57:25.253 に答える
3

あなたのアプリケーションがファイル名として '-' をサポートしていない場合 (サポートすべきである場合) は、別の方法として名前付きパイプを使用することもできます。

pipe='/tmp/pipe'
mkfifo "$pipe"

gpg --recipient someone@example.com --armor --output "$pipe" --encrypt example.pdf &

while read 
do
    echo "$REPLY"
done < $pipe

rm "$pipe"
于 2012-06-26T08:03:40.147 に答える
2

gnupg マニュアルに基づく

--output を単に省略します。

于 2012-06-26T05:02:44.610 に答える