Reading ShellExecute () output file in Delphi 2010?

I use the ShellExecute command to run an exe file that receives an input text file and returns an output text file. I wrote it like this:

ShellExecute(mainFormHandle, 'open', 'Test.exe',
    'input.txt output.txt', nil, sw_shownormal);

//Read the output file...
S_List.LoadFromFile('output.txt');
Writeln(S_List[0])

Before executing this command, I provide the input.txt file. At each start of my program, the input file is changed, as well as the output file.

The problem is this: I do not see the changes in the output file! A line written in the console refers to the previous file, not the new one. I mean, the file in explorer is modified, but the file I read is still the old file.

It seems a little strange, but I was wondering if there is a way to update the output file before reading it? Or am I missing something here?

Thanks in advance.

+3
1

ShellExecute . :

  • Test.exe
  • output.txt
  • Test.exe output.txt

- :

var
  StartUpInfo : TStartUpInfo;
  ProcessInfo : TProcessInformation;
  CreationFlags : Cardinal;
begin
  FillChar(StartUpInfo, SizeOf(TStartupInfo),0);
  StartupInfo.cb := SizeOf(TStartupInfo);
  CreationFlags := Normal_Priority_Class;

  if CreateProcess(nil, 'test.exe input.txt output.txt',
               nil, nil, False, CreationFlags,
               nil, 0, StartupInfo, ProcessInfo) then
  begin
    WaitforSingleObject(ProcessInfo.HProcess, INFINITE);
    CloseHandle(ProcessInfo.HProcess);

    //Read the output file...
    S_List.LoadFromFile('output.txt');
  end;

WaitForSingleObject .

+11

Source: https://habr.com/ru/post/1752279/


All Articles