Getting Statistics::R to work with PerlApp (or PAR)

529 views Asked by At

I'm trying to make an .exe from a simple perl script that uses the Statistics::R package.

use Statistics::R;
use strict;
my $R = Statistics::R->new();
$R->startR;
$R->send('x=10');
$R->send('x');
my $ret = $R->read;
print $ret;
$R->stopR();

Everything works fine until I create the perlapp .exe file. When I test this, I get the following errors:

Inappropriate I/O control operation: Win32::Process::Create() at /<C:\@programming\r\trying_r_bridge.exe>IPC/Run.pm line 2105
Inappropriate I/O control operation: Win32::Process::Create() at /<C:\@programming\r\trying_r_bridge.exe>IPC/Run.pm line 2224
Inappropriate I/O control operation: Win32::Process::Create() at /<C:\@programming\r\trying_r_bridge.exe>IPC/Run.pm line 2224

I looked online and found this thread about the problem: http://www.nntp.perl.org/group/perl.par/2011/05/msg5022.html

This is what they say:

this happens because the IPC::Run module on Win32 (only) tries to run subprocesses using $^X, which normally contains the path to perl.exe. However, when PAR packs an executable, $^X doesn't happen to point to perl.exe, and so IPC::Run fails at that point. Implementing IPC::Run on Windows without using subprocesses is an unsolved problem.

In the end, the thread solution is to use IPC::Run3, which is not an option here.

Any suggestions for how to overcome this problem?

2

There are 2 answers

1
Florent Angly On

I have rewritten almost entirely Statistics::R in the last year to make it faster, platform-independent and robust. I chose to perform the calls to R and various IOs through IPC::Run.

Apparently, the issue seems you describe is specific to IPC::Run. So, you should first file a ticket on the IPC::Run tracker. I do not know how feasible for the authors of IPC::Run to implement a fix, but the least they can do is have a caveat section that describes the incompatibility.

Using IPC::Run3 instead of IPC::Run in Statistics::R may be an option if it satisfies the requirements of Statistics::R (mainly communicate with R using stdin, stdout and stderr). It would not a drop-in replacement, so, not a trivial change.

4
singingfish On

I think you're doomed. Just don't make an .exe file - use strawberry portable, and a batch/vbs script to run your stuff. Statistics::R is a pretty fragile implementation IIRC. I'd like to see someone sponsor development of a better, platform independent R/perl connector. Meanwhile here's a batch script you can adapt:

  echo off
  set bindir=%~dp0
  set perlpath=%bindir%perl\bin
  set buildpath=%bindir%\bin
  set PATH=%PATH%;%perlpath%;%buildpath%
  "%perlpath%\perl.exe" "%bindir%myscript.pl

And here's the VBS script to run the batch script without setting up a cmd window:

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  WshShell.Run chr(34) &  fso.GetParentFolderName(wscript.ScriptFullName) & "\perlshell.bat"& Chr(34), 0
  Set WshShell = Nothing