Hi
Hi
i'm trying to run CMD keep it running and pass parameters to it tired this
begin
ShellExecute(Handle, nil,
'cmd.exe','
/K "C:\pgsql\bin\pg_ctl" -D "C:\pgsql\bin\/data" -l logfile start',
nil,
SW_SHOWNORMAL);
end;
i got the error:
"filename directory name or volume label syntax is incorrect"
i also tried :
var Source : string;
begin
Source := Trim( '/K "C:\pgsql\bin\pg_ctl" -D "C:\pgsql\bin\data" -l logfile start');
ShellExecute(Handle, nil, 'cmd.exe', PChar(Source) , nil, SW_SHOWNORMAL);
end;
got the same error
i'm trying to run CMD keep it running and pass parameters to it tired this
begin
ShellExecute(Handle, nil,
'cmd.exe','
/K "C:\pgsql\bin\pg_ctl" -D "C:\pgsql\bin\/data" -l logfile start',
nil,
SW_SHOWNORMAL);
end;
i got the error:
"filename directory name or volume label syntax is incorrect"
i also tried :
var Source : string;
begin
Source := Trim( '/K "C:\pgsql\bin\pg_ctl" -D "C:\pgsql\bin\data" -l logfile start');
ShellExecute(Handle, nil, 'cmd.exe', PChar(Source) , nil, SW_SHOWNORMAL);
end;
got the same error
Why ShellExecute? CreateProcess creates processes. Why cmd.exe? Why not start the exe directly?
ReplyDeleteFor some reason he wants to keep cmd running after the command completes.
ReplyDeleteThis is to run the PostgreSQL database server without installing it , to keep the server running the cmd should stay open if i open the cmd and type the parameters it works just fine , but i wanna do that through Delphi
ReplyDeleteHamza Benzaoui What happens if you create a batch file (.bat) with your command and run this .bat instead?
ReplyDeleteYou don't need cmd.exe at all
ReplyDeleteMocte Sandoval i did this and it's working just fine but i'm trying to hide the black screen when the server starts
ReplyDeleteDavid Heffernan i didn't understand what are you trying to say , if i dont need cmd.exe what i need ?
ReplyDeleteYou are using cmd.exe simply to start another process. Cut out the middle man and start that process directly with a call to CreateProcess passing the command line for that other process.
ReplyDeleteThat is, use CreateProcess to execute pg_ctl directly. After all, what do you think cmd is going to do other than call CreateProcess to launch pg_ctl. You might as well do it directly.
I've had issues with CreateProcess for some applications, which was resolved by using ShellExecuteEx. The latter seems to handle paths and environment variables better without doing explicit parameterization.
ReplyDeleteLars Fosdal ShellExecuteEx just calls CreateProcess to create processes. CreateProcess is a tricky function to call that is true. You probably just didn't understand how to handle the first two arguments.
ReplyDeleteDavid Heffernan. AFAIK, CreateProcess doesn't handle App paths. https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121.aspx
ReplyDeleteShellExecuteEx does.
Another thing that is easier with ShellExecuteEx, is UAC elevation.
Elevation without manifest requires ShellExecuteEx. And yes, app paths are part of the shell so again ShellExecuteEx.
ReplyDeleteNeither of those concerns are relevant here are they?
The code in the original post is odd because it has so much indirection. It calls ShellExecuteEx which in turn calls CreateProcess for cmd.exe which in turn calls CreateProcess for pg_ctl.exe. All rather pointless. May as well cut out the first two steps.
Thanks a lot guys :D
ReplyDelete