Can't correct error "Can not write to file.csv No such file or directory".  HELP PLEASE!

Posted on 2004-03-20
Last Modified: 2013-12-25
I am getting the following error:
Software error:
Can not write to file.csv No such file or directory

I have tried everything I can think of.

Using path: "$htmlpath/file.csv" (where htmlpath =  '/home/chrono/public_html'):
The same error appears if I upload a blank text file called "file.csv" or not or chmod this "file.csv" to 777 or not.

Using no path (just "file.csv"):
If I upload a blank file.csv into the cgi-bin, it seems to work (no error message) but it refuses to download and seems to be empty (0k).

It may be a simple error but I can't see it. Your help would be greatly appreciated.

use strict;                  
use CGI;
use CGI::Carp qw(fatalsToBrowser);

use lib "/your/modules/path";  # Location of the Email::Valid module
use Email::Valid;

my $mail_prog = '/usr/sbin/sendmail' ;
my $your_email = '';
my $your_comments = "Thank you for using our online form. We will reply as soon as we can.";
my $htmlpath = '/home/chrono/public_html';

my $q = new CGI;

my $name = $q->param('name');
my $email = $q->param('email');
my $subject = $q->param('subject');
my $comments = $q->param('comments');

print_error("You must enter your name") unless $name;
print_error("You must enter your email address") unless $email;
print_error("You must enter a subject") unless $subject;
print_error("You must enter your comments") unless $comments;

print_error("Your email address is invalid") unless Email::Valid->address($email);

open MAIL, "|$mail_prog -oi -t" or die "Can not start $mail_prog $!\n";
print MAIL <<EOF;
To: $email
Reply-to: $your_email
From: $your_email
Subject: Thank You



close MAIL;

open MAIL, "|$mail_prog -oi -t" or die "Can not start $mail_prog $!\n";
print MAIL <<EOF;
To: $email
Reply-to: $email
From: $email
Subject: reply from our form



close MAIL;

print $q->header;

print <<HTMLCODE;
<title>Thank You</title>


<p align="center"><font color="#ffffff" face="Arial"><big><strong>Thank You, $name!</strong></big></font></p>

<p align="left">&nbsp;</p>


<p align="left"><font face="Arial" color="#000080"><big>You entered the following:</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Name: $name</big></font></p>

<p align="left"><font face="Arial" color="#000080"><big>Email: $email</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Subject: $subject</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Comments: $comments </big></font></p>


#Print to file

open CSV, "$htmlpath/file.csv" or die "Can not write to file.csv $!\n";
print CSV "$name,$email,$subject,$comments\n";
close CSV;


sub print_error {
        my $message = shift;

        print $q->header;

        print <<HTMLCODE;


<p align="center"><font color="#ffffff" face="Arial"><big><strong>Processing Error</strong></big></font></p>

<p align="left"><font face="Arial" color="#000080"><strong>$message</strong></font></p>

<p align="left"><font face="Arial" color="#000080"><strong>Please click your browser's Back button and try again.</strong></font></p>


Question by:rincewind666
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 12

Expert Comment

ID: 10642035

Is it giving the correct path when you try to print out the string "$htmlpath/file.csv"??

Author Comment

ID: 10643494
It is the correct path. It works with other cgi scripts I use.  Also I've tried it without the variable: '/home/chrono/public_html/file.csv' and it still doesn't work. Thanks for the help.

The perl code is above.  I also give my html code for the initial page below.  Perhaps you can try it out:


<TABLE borderColor=#000000 cellSpacing=1 cellPadding=1 width="75%"
bgColor=#ffffff background=000000>
    <TD>Name: <INPUT name=name></TD></TR>
    <TD>Email: <INPUT name=email></TD></TR>
    <TD>Subject: <INPUT name=subject></TD></TR>
    <TD><TEXTAREA name=comments rows=5 cols=30></TEXTAREA></TD></TR>
    <TD><INPUT type=submit value=Submit>&nbsp;&nbsp; <INPUT type=reset value=Reset></TD></TR>

LVL 48

Accepted Solution

Tintin earned 500 total points
ID: 10646151
There's a missing > in the open

open CSV, "$htmlpath/file.csv" or die "Can not write to file.csv $!\n";

should be:

open CSV, ">$htmlpath/file.csv" or die "Can not write to file.csv $!\n";

If it works without the $htmlpath, then you might as well remove it.

Author Comment

ID: 10665792
Many thanks for your help.

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove all hidden metadata properties of MS .Docx Files 7 57
Awk : two files math 8 42
storing csv file in table variable in Python 2 94
-OutVariable to Global 1 32
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question