0

If I run the commands bellow, only out1 has output, the out2 and out3 are empty.

# this is just to generate a self-signed certificate
openssl genrsa -out /tmp/ssl.key 2048
openssl req -sha256 -new -key /tmp/ssl.key -out /tmp/ssl.csr -subj /CN=localhost
openssl x509 -req -days 365 -in /tmp/ssl.csr -signkey /tmp/ssl.key -out /tmp/ssl.crt

# works
openssl s_server -cert /tmp/ssl.crt -key /tmp/ssl.key -accept 444 > out1
# does not work, but if I run without '> out2' it works
openssl s_server -cert /tmp/ssl.crt -key /tmp/ssl.key -accept 446 | sed "s/ACCEPT/ACCEPT445/g" > out2
# does not work, but if I run without '> out3' it works
openssl s_server -cert /tmp/ssl.crt -key /tmp/ssl.key -accept 447 | grep ACCEPT > out3

Why does redirecting stdout from sed or grep fail, but running without redirecting works ?

2

Try the sed -u (-lon BSD/Mac OSX systems), and grep --line-bufferedoptions.

1

You seem to expect the out2 and out3 being written in real time, but sed and grep in pipe wait for the EOF. And nothing fails here.

Kill openssl from another console and check if you have correct results in out2 and out3.

  • sed and grep don't wait for the EOF regardless of whether they're in pipes or not; however pipes themselves are buffered. sed and grep handle the input as soon as they see it. – Wildcard Apr 4 '16 at 22:42
  • You are correct, killing openssl will have correct results in out2 and out3. How could I go around this without killing openssl? – Chris Apr 4 '16 at 22:46
  • Wasn't your original question why it did not work? – techraf Apr 4 '16 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.