Geule 0 Posted January 10 Hello! I can run openssl commands directly from the Windows prompt and it runs normally. But how can I do this directly in Delphi. MS-DOS commands run normally in Delphi. But openssl commands don't. Anyone who can help me with this? A simple example that I'm trying to run: "openssl version" Share this post Link to post
dummzeuch 1505 Posted January 10 And what happens, if you try to run it? Are there any error messages? How do you try to run it? Share this post Link to post
Remy Lebeau 1394 Posted January 10 (edited) 3 hours ago, Geule said: how can I do this directly in Delphi. Use the Win32 CreateProcess() function. Of course, a better option might be to NOT shell out to openssl.exe at all, but to use the OpenSSL API directly in your own code instead. It really depends on what you are trying to accomplish exactly. 3 hours ago, Geule said: MS-DOS commands run normally in Delphi. Only if you execute them as parameters to cmd.exe. 3 hours ago, Geule said: But openssl commands don't. Then you are doing something wrong, but we can't see what you are actually doing. Please show your actual code you are having trouble with. 3 hours ago, Geule said: Anyone who can help me with this? A simple example that I'm trying to run: "openssl version" For example: uses ..., Windows; procedure RunCommandLine(CmdLine: String); var si: TStartupInfo; pi: TProcessInformation; begin {$IFDEF UNICODE}UniqueString(CmdLine);{$ENDIF} ZeroMemory(@si, SizeOf(si)); si.cb := SizeOf(si); if not CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, si, pi) then RaiseLastOSError; ... CloseHandle(pi.hThread); CloseHandle(pi.hProcess); end; ... RunCommandLine('C:\path\openssl.exe version'); Just note that openssl.exe is a console app, so if you run this code in a non-console program, it will create a new console that will close when openssl.exe exits. If you actually want to see the console window to read the output, or even to capture the output into your own code, requires more work than this code shows. Edited January 11 by Remy Lebeau Share this post Link to post
Geule 0 Posted January 11 2 hours ago, dummzeuch said: And what happens, if you try to run it? Are there any error messages? How do you try to run it? Prompt open and close quickly... Share this post Link to post
Geule 0 Posted January 11 2 hours ago, Remy Lebeau said: Use the Win32 CreateProcess() function. Of course, a better option might be to NOT shell out to openssl.exe at all, but to use the OpenSSL API directly in your own code instead. It really depends on what you are trying to accomplish exactly. Only if you execute them as parameters to cmd.exe. Then you are doing something wrong, but we can't see what you are actually doing. Please show your actual code you are having trouble with. For example: uses ..., Windows; procedure RunCommandLine(CmdLine: String); var si: TStartupInfo; pi: TProcessInformation; begin ZeroMemory(@si, SizeOf(si)); si.cb := SizeOf(si); if not CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, si, pi) then RaiseLastOSError; ... CloseHandle(pi.hThread); CloseHandle(pi.hProcess); end; ... RunCommandLine('C:\path\openssl.exe version'); Just note that openssl.exe is a console app, so if you run this code in a non-console program, it will create a new console that will close when openssl.exe exits. If you actually want to see the console window to read the output, or even to capture the output into your own code, requires more work than this code shows. I got this error Access violation KERNELBASE.dll OpenSSL version installed 3.2.0 23 Nov 2023 Share this post Link to post
Remy Lebeau 1394 Posted January 11 (edited) 13 minutes ago, Geule said: I got this error Access violation KERNELBASE.dll I updated my earlier example. Make sure CmdLine is not pointing at a string literal when passing it to CreateProcess(), as the 2nd parameter of the Unicode version of CreateProcess() (CreateProcessW) is not allowed to point at read-only memory. Edited January 11 by Remy Lebeau Share this post Link to post
Geule 0 Posted January 11 19 minutes ago, Remy Lebeau said: I updated my earlier example. Make sure CmdLine is not pointing at a string literal when passing it to CreateProcess(), as the 2nd parameter of the Unicode version of CreateProcess() (CreateProcessW) is not allowed to point at read-only memory. With the Unicode directive it worked just fine! And best of all, it worked in my own code! Thank you very much! Share this post Link to post
FPiette 383 Posted January 13 Warning: This is not a direct answer to your question. Instead of running OpenSSL command line tool from your Delphi application, you can directly call OpenSSL API. This is what ICS does. ICS covers a large part of OpenSSL API and call OpenSSL DLL. If you need help with ICS, the is a dedicated forum on this website : https://en.delphipraxis.net/forum/37-ics-internet-component-suite/ 1 Share this post Link to post