views:

309

answers:

2

I've written a little ruby script that lets me send emails by calling it along with some command line parameters.

At the command line, this works:

ruby.exe mail_it.rb fromaddr="[email protected]" tolist="[email protected]"

But try as I may, I can't get it to work in Delphi 2007 for Win32. Here's the latest attempt:

procedure TForm1.Button1Click(Sender: TObject);
var
  params: string;
begin
  params:= 'mail_it.rb fromaddr="[email protected]" tolist="[email protected]"';
  caption:= IntToStr(ShellExecute(Form1.Handle, nil, PChar('ruby.exe'), PChar(params), nil, SW_SHOW));
end;

I've tried using 'open' as the second param in ShellExecute, but it doesn't help. ShellExecute itself returns 42, which as far as I can tell from what I've found on other websites means "no error".

+1  A: 

try this:

shellexecute(0, 'open', '<PUT YOUR PATH HERE>\mail_it.rb', fromaddr="[email protected]" tolist="[email protected]"' , nil, SW_NORMAL);

i don't have ruby installed, but this works for me starting a .pas file with the editor. as long as you have ruby.exe associated with .rb files, it should work.

-don

Don Dickinson
I'll give it a shot. Reason I'm dubious is because I don't need the path normally as all the ruby stuff is in the system path, one way or another. I'll repost when I've tried it
It worked! Many thanks!
Would you mind fixing the syntax, please? It's not clear from this what you meant to write.
Rob Kennedy
@Rob Kennedy: please see below.
A: 

Here's the minimal code that works:

procedure TForm1.Button1Click(Sender: TObject);
var
  params: string;
begin
    shellexecute(0, nil, 'mail_it.rb', 
                 'fromaddr="[email protected]" tolist="[email protected]"', 
                  nil, SW_NORMAL);
end;

I did NOT need the full path to mail_it.rb, nor the 'open', but I DID need the '.rb'.