RoutineOp / delphi-code-coverage

Automatically exported from code.google.com/p/delphi-code-coverage
0 stars 1 forks source link

Executable does not see passed arguments #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The new code in version 0.2 correctly reads the parameter arguments from the 
command line. However, in tests with Delphi 2009, the executable does not 
receive the passed parameters. ParamCount always returns 0.

I have added a debug line in StartProcessToDebug and changed the types to 
PWideChar. Maybe there is a problem with CreateProcess? I am using jwa 2.3 from 
June 25.

function TDebugger.StartProcessToDebug(executable: string): Boolean;
var
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CreateOK: Boolean;
  exe, parameters: PWideChar;
begin
  exe := pwidechar(executable);
  parameters := Pwidechar(Configuration.getApplicationParameters);
  writeln('passing: ' + parameters);

  fillchar(StartInfo, sizeof(TStartupInfo), #0);
  fillchar(ProcInfo, sizeof(TProcessInformation), #0);
  StartInfo.cb := sizeof(TStartupInfo);
  CreateOK := CreateProcess(exe, parameters, nil, nil, false,
    CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS + DEBUG_PROCESS, nil, nil, StartInfo, ProcInfo);
  result := CreateOK = true;
end;

Original issue reported on code.google.com by michael....@gmx.net on 30 Jun 2010 at 10:37

GoogleCodeExporter commented 9 years ago
I have just came across this issue too and it seems that the first argument is 
"disappearing". What I have found is that the CreateProcess is working 
correctly but it is how the application receives the command line information.

Work around: 

Put a dummy command line argument as the first argument (such as the 
executable).

Code fix:

function TDebugger.StartProcessToDebug(executable: string): Boolean;
var
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  parameters: string;
begin
  parameters := Configuration.getApplicationParameters;
  log.log('Trying to start ' + executable + ' with the parameters :' + parameters);
  fillchar(StartInfo, sizeof(TStartupInfo), #0);
  fillchar(ProcInfo, sizeof(TProcessInformation), #0);
  StartInfo.cb := sizeof(TStartupInfo);
  parameters := '"' + executable + '" ' + parameters;
  result := CreateProcess(nil, pchar(parameters), nil, nil, false,
    CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS + DEBUG_PROCESS, nil, nil, StartInfo, ProcInfo);
end;

Original comment by ring....@gmail.com on 10 Aug 2010 at 8:56

GoogleCodeExporter commented 9 years ago

Original comment by ring....@gmail.com on 20 Oct 2011 at 12:42