davies has asked for the wisdom of the Perl Monks concerning the following question:

I have a SSCCE, DebugR.cgi:

#!c:/Strawberry/Perl/bin/perl use strict; use warnings; use Statistics::R; use CGI qw(:standard escapeHTML -utf8); print header(-type=>'text/html', -charset=>'utf-8'); my $R = Statistics::R->new(); print "R created\n"; $R->run('options(scipen = 999)'); # disabling scientific notation i +n R. print "R initialised\n";

Running this from the command line works as expected:

C:\Information\mgroot\cgi-bin>perl DebugR.cgi Content-Type: text/html; charset=utf-8 R created R initialised

But pointing a browser to it via an Apache web server results in only the "R created" line and the following errors in the log:

[Wed Jan 29 13:58:44 2020] [error] [client 192.168.1.207] ack Invalid +argument: write( 5, 'cmd<-c("write(ngettext(1, \\"Error: \\", \\"\\", + domain=\\"R\\"), stdout())"); write("\\1",stdout()) [Wed Jan 29 13:58:44 2020] [error] [client 192.168.1.207] ' ) at C:/St +rawberry/perl/vendor/lib/IPC/Run/IO.pm line 549. [Wed Jan 29 13:58:44 2020] [error] [client 192.168.1.207] Warning: una +ble to close filehandle GEN10 properly: Bad file descriptor during gl +obal destruction. [Wed Jan 29 13:58:44 2020] [error] [client 192.168.1.207] Warning: una +ble to close filehandle GEN5 properly: Bad file descriptor during glo +bal destruction.

It is not obvious to me why there should be a difference or where to start looking next. Any clues would be appreciated.

Regards,

John Davies

Replies are listed 'Best First'.
Re: Apache causing R to crash
by Fletch (Bishop) on Jan 29, 2020 at 15:18 UTC

    Were this some flavour of *NIX I'd guess that R might be expecting a tty (or at least pty) and something about being run from an apache context rather than from your shell cmd prompt isn't providing it one. But that's purely speculation and probably not germane.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Windows comms between Statistics::R and R itself are, AFAICT, handled by IPC::Run, which seems to be reporting the problem. But I don't know enough about Apache to be able to guess how it would affect the comms.

      Regards,

      John Davies

Re: Apache causing R to crash
by Anonymous Monk on Jan 30, 2020 at 00:58 UTC