views:

50

answers:

1

I have a project on Lazarus that I want to compile a source using gcc, for this I have a TOpenDialog called OpenDialog1 and a TProcess called AProcess.

I call gcc with this code:

procedure TFormMain.btCompileClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    AProcess := TProcess.Create(nil);
    try
      AProcess.CommandLine := 'gcc.exe ' + OpenDialog1.FileName;
      AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
      AProcess.Execute;
      OutputMemo.Lines.BeginUpdate;
      OutputMemo.Lines.Clear;
      OutputMemo.Lines.LoadFromStream(AProcess.Output);
      OutputMemo.Lines.EndUpdate;
    finally
      AProcess.Free;
    end;
  end;
end;

It compiles ok(the project on Lazzarus), but when I was testing it, by trying to compile the source test.c, that is located at C:\Documents and Settings\Nathan Campos\Desktop, I got this on OutputMemo:

'C:\Documents': No such file or directory

Then, OpenDialog1 isn't getting the full path with the spaces, or gcc can't locate it on the folder with spaces.

Any suggestion to help me on this?

+5  A: 

It needs to be in quotes so spaces won't trip it up. So like this:

AProcess.CommandLine := 'gcc.exe "' + OpenDialog1.FileName + '"';

That should work.

Mason Wheeler
Thanks very much! I've forgot about this, sorry to make you loose your time **:(**
Nathan Campos