Search code examples
rubydelphishellexecute

run a ruby script from delphi via shellexecute


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="mailaddr1@gmail.com" tolist="mailaddr2@yahoo.com"

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="mailaddr1@gmail.com" tolist="mailaddr2@yahoo.com"';
  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".


Solution

  • try this:

    shellexecute(0, 'open', '<PUT YOUR PATH HERE>\mail_it.rb', fromaddr="mailaddr1@gmail.com" tolist="mailaddr2@yahoo.com"' , 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