Script filling password from command line

I have this command that i am calling from php (exec()):

openssl pkcs12 -export -in cert.pem -inkey key.pem -out cred.p12

and then i need to insert password twice

Enter Export Password:

Verifying - Enter Export Password:

I need script that will fill the password inputs,because exec() will only do that command, but not insert password twice. Do you have any idea how should i do it?

You may be able to do it with popen:

$f=popen("openssl pkcs12 -export -in cert.pem -inkey key.pem -out cred.p12", "w");

fwrite($f, "password\n");
fwrite($f, "password\n");
pclose($f);

If that doesn't work, it may be demanding a terminal for password inputs, which would make automating it extremely difficult.

How about setting an environment variable with the password (eg putenv("INPASS=secret"); )
and using the -passin env: option of openssl -passin env:INPASS

Any other process on the system may be able to read that password in transit when you put it in the environment, though it's not as obvious as making it a parameter.