Richard TANG
Richard TANG

Reputation: 1

Writing to a text file using Perl CGI

I am using cgi to call a perl function, and inside the perl function, I want it to write something in a txt. But it's not working for now. I have tried to run the cgi script on my apache server. The cgi could print the webpage as I requied, but I can't see the file that I want it to write. Seems like the perl script is not execute by the server.

The perl script is quite simple.The file name is perl predict_seq_1.pl

#!/usr/bin/perl -w
use strict;
use warnings;


my $seq = $ARGV[0];
my $txtfile = "test.txt";
open(my $FH, '>', $txtfile);
print $FH "test $seq success\n";
close $FH;

And the cgi part, I just call it by

system('perl predict_seq_1.pl', $geneSeq);

Upvotes: 0

Views: 571

Answers (2)

Ed Grimm
Ed Grimm

Reputation: 558

Either give system a single string, or give it individual arguments. Your script is attempting and failing to run the program perl predict_seq_1.pl, rather than having perl run the script predict_seq_1.pl.

system('perl', 'predict_seq_1.pl', $geneSeq);

Upvotes: 0

Dave Cross
Dave Cross

Reputation: 69314

Your CGI program is going to run by a user who has very low permissions on your system - certainly lower than your own user account on that same system.

It seems likely that one of two things is happening:

  1. Your CGI process can't see the program you're trying to run.
  2. Your CGI program doesn't have permission to execute the program you're trying to run.

You should check the return value from system() and look at the value of $?.

Upvotes: 1

Related Questions