Automatically enter user input several times to command stdin

I need to perform a conversion of digital certificates from pfx to pem on an external application from which I can run system commands. I can do this from CLI by using the command:

openssl pkcs12 -in path/to/cert.pfx -out path/to/cert.pem 

This will prompt the user for the certificate password, and secondly, for a passphrase.

I've tried the solution provided here: Automatically enter input in command line

And it is not working for me. So, if I try (note the line breaks):

printf 'the_password\nthe_passphrase\n' | openssl pkcs12 -in path/to/cert.pfx -out path/to/cert.pem 

It will still ask me for the password and passphrase. I also tried using echo, without success.

Any ideas?

EDIT:

Following Level9's advice, I've tried using openssl options, like this:

openssl pkcs12 -in path/to/cert.pfx -out path/to/cert.pem -password pass:the_password -passout pass:

I've tried both providing a passphrase and not, like in the example. Now it generates the pem file, but if I try to open it from my file system, just to check if it's correct, then I'm asked for the password, but it will not accept the one I provided in the command line.


Solution 1:

Have a look at the options for specifying passwords in openssl.

openssl pkcs12 -help

If that doesn't work for you then try the "expect" utility.

sudo apt install expect