Jumpei Ogawa
Jumpei Ogawa

Reputation: 504

Write to stdout instead of file

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 [email protected] --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 [email protected] --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.

Upvotes: 4

Views: 6411

Answers (3)

cdarke
cdarke

Reputation: 44354

If your application does not support '-' as a filename (and it should) then an alternative is to use a named pipe, although I'll admit this looks like using a sledgehammer to crack a nut:

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

gpg --recipient [email protected] --armor --output "$pipe" --encrypt example.pdf &

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

rm "$pipe"

Upvotes: 3

viclim
viclim

Reputation: 959

Based on the gnupg manual

Simply omit the --output.

Upvotes: 2

bos
bos

Reputation: 6535

Usually you use "-" to specify stdout, but not all commands accept this and I don't about gpg.

For example:

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

will pipe the "tar-file" to stdout, split it and save to "foobar_<123...>".

Upvotes: 6

Related Questions