Gentlepersons:

A long time ago I used to be able to start R (version 2.6.1) from a Delphi 7 program and run a script by using a procedure like the following:

function StartRAndWait (CommandLine : string) : Boolean;
var
   Proc_info: TProcessInformation;
   Startinfo: TStartupInfo;
   ExitCode: longword;
   CreateOK : Boolean;
begin
   Result := False;

   { Initialize the structures }

   FillChar(proc_info, sizeof (TProcessInformation), #0);
   FillChar(startinfo, sizeof (TStartupInfo), #0);
   Startinfo.cb := sizeof (TStartupInfo);
   Startinfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
   Startinfo.wShowWindow := SW_HIDE;

   { Attempt to create the process. If successful wait for it to end}

   // CreateOK := CreateProcess(nil, nil, nil, nil, nil,
CreateOK := CreateProcess(Nil, PChar('C:\Program Files\R\R-2.8.1\bin\R.exe '
      + CommandLine), nil, nil,
      False, CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, nil, nil,
      StartInfo, proc_info);
   if (CreateOK) then begin
      WaitForSingleObject (proc_info.hProcess, INFINITE);
      GetExitCodeProcess(proc_info.hProcess, ExitCode);
      Result := True
      end;
   CloseHandle(proc_info.hThread);
   CloseHandle(proc_info.hProcess);
   end;

Now it seems to hang on the call on WaitForSingleObject toward the end. My current version of R is 2.8.1 if that is relevant. Does anybody have any suggestions?

Tom

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to