Hi,
I am trying to execute a command using delphi, as if I had typed it into the windows command prompt.
I am using this code to do it:
This definatley works with at least some commands, for example the net send command.
However, I am trying to use it to create a text file with a directory listing.
If you open up a command prompt and type "dir C:\ > C:\hello.txt" then it dumps the output of the command to C:\hello.txt.
Try it yourself, it works.
But, when I try it in delphi, it doesnt work
Can anyone suggest why it wouldnt work, how to fix it, or any alternatives?
Thanks,
kr0me
I am trying to execute a command using delphi, as if I had typed it into the windows command prompt.
I am using this code to do it:
Code:
function OpenCmdLine(const CmdLine: string;
WindowState: Word): Boolean;
var
SUInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
{ Enclose filename in quotes to take care of
long filenames with spaces. }
FillChar(SUInfo, SizeOf(SUInfo), #0);
with SUInfo do
begin
cb := SizeOf(SUInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := WindowState;
end;
Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS, nil,
nil {PChar(ExtractFilePath(Filename))},
SUInfo, ProcInfo);
end;
This definatley works with at least some commands, for example the net send command.
However, I am trying to use it to create a text file with a directory listing.
If you open up a command prompt and type "dir C:\ > C:\hello.txt" then it dumps the output of the command to C:\hello.txt.
Try it yourself, it works.
But, when I try it in delphi, it doesnt work
Can anyone suggest why it wouldnt work, how to fix it, or any alternatives?
Thanks,
kr0me