moedermaria
asked on
c++, give input to dos prompt with command 'system'
hi,
i'm using c++ builder 6 and i'm writing a program here at work. this problem came up:
i want to decrypt a rsa private key in my program. now i can give one dos-command to the promptand will be executed fine:
AnsiString command.sprintf("openssl rsa -in %s -out %s",inputfile,outputfile);
system(command.c_str());
after this line the command prompt waits for the password so i have to enter the password using the keyboard. i don(t want this i want to be able to pass the password to the command prompt so that my key will be decrypted without having to interfere manually.
if this cannot be done in C++ plz advise on a batch file that does the same...
greetz, drizzz
i'm using c++ builder 6 and i'm writing a program here at work. this problem came up:
i want to decrypt a rsa private key in my program. now i can give one dos-command to the promptand will be executed fine:
AnsiString command.sprintf("openssl rsa -in %s -out %s",inputfile,outputfile);
system(command.c_str());
after this line the command prompt waits for the password so i have to enter the password using the keyboard. i don(t want this i want to be able to pass the password to the command prompt so that my key will be decrypted without having to interfere manually.
if this cannot be done in C++ plz advise on a batch file that does the same...
greetz, drizzz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> wrote this already in the duplicated question;-)
Actually, you wrote it in the duplicate question, this one is the original. :-)
Besides, assuming this does work, it is still much simpler to use popen() because it returns a FILE pointer and you can write DIRECTLY into the sub process' stdin stream. :-)
Exceter
Actually, you wrote it in the duplicate question, this one is the original. :-)
Besides, assuming this does work, it is still much simpler to use popen() because it returns a FILE pointer and you can write DIRECTLY into the sub process' stdin stream. :-)
Exceter
OK, Exceter your completly right, but ...
I tried to build a little Prog with popen, and the linker can't find this function!
So i tried it on a UNIX-Machine and it worked!
Are you sure this function is avaiable to DOS???
Regards
AZ
I tried to build a little Prog with popen, and the linker can't find this function!
So i tried it on a UNIX-Machine and it worked!
Are you sure this function is avaiable to DOS???
Regards
AZ
>> ...and the linker can't find this function!
popen() is found in stdio.h and, unless you are using C++, I doubt that you forgot to include this as you would not be able to write to stdout. What compiler are you using? If you are using a Microsoft compiler try placing an underscore before the function name. For example,
if( (chkdsk = _popen( command.c_str(), "wt" )) == NULL )
...
printf( "\nProcess returned %d\r\n", _pclose( chkdsk ) );
Exceter
popen() is found in stdio.h and, unless you are using C++, I doubt that you forgot to include this as you would not be able to write to stdout. What compiler are you using? If you are using a Microsoft compiler try placing an underscore before the function name. For example,
if( (chkdsk = _popen( command.c_str(), "wt" )) == NULL )
...
printf( "\nProcess returned %d\r\n", _pclose( chkdsk ) );
Exceter
moedermaria:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Points to: Exceter.
wrote this already in the duplicated question;-)
you can create a answer file and redirect stdin!!
TRy something like this(but i dont know if it will work with pwd):
echo testpwd > answer.txt
myapp.exe < answer.txt
Then when your prog read from stdin it will get the first line, second read->second line and so on!
Regards
AZ