[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

open file problem

hi experts!
i have a script that can read a text file. this script runs perfectly when i user free server(virtualave). but when i try to rent a server from my country, it seems that the problem occurs. the server runs in NT. Below is part of the script.

sub open_file {

  local ($filevar, $filemode, $filename) = @_;
 
  open ($filevar,$filemode . $filename) ||
     die ("Can't open $filename");
}

above is the sub to  open the file.

 &open_file("FILE1","",$filename);

and this is the program that runs that function.

the problem is, when i run it, errors appear.the error is:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

cannot return text file(test.txt) at the following line..
open ($filevar,$filemode . $filename) ||
die ("Can't open $filename");


but this program runs smoothly when i try with virtualave.
hope someone can help.
0
kudak
Asked:
kudak
  • 2
  • 2
1 Solution
 
guadalupeCommented:
Try this a see what it tells you:


   
  open ($filevar,$filemode . $filename) ||
     (print ("Content-type: text-plain\n\nError codes: $! - $?") && exit);


Also check and see if the file you are trying to open  has the necessary permissions.
 
0
 
kudakAuthor Commented:
ok guadalupe, i've tried yours and this problem occurs.
first, it prompts me to download the perl file.
second wehen i open that perl file, this wording appears:
Error codes: No such file or directory - 0
0
 
kudakAuthor Commented:
i've chmoded the perl file and my text file to 755.
0
 
KennyIT Application ExecutiveCommented:
Try putting this line in the beginning of your original code. (the one which works on the other server) :

print "Content-type: text/html","\n\n";
0
 
guadalupeCommented:
If you are promted to download to file it sounds like your server is not corectly configured to run ALL perl files.  I say all because mabe it will run cgi but not pl (I don't know which extension your script has)  But configuration definitly sound like it could be part of the problem.  Then there is the obvious No such file or directory.  The difference is that obiously you dont see this file from a web browser point of view though you do from the command line.  This could be a number of things.  Maybe your variables get correctly set in the command line run and so a full qualified path results, but when run from the  browser for some reason the variables are not set and cause an incomplete path to be specified(?).  Then there are permissions and such.  I would attack configuration first.  Make a stupid little "hello world" prog and make sure it runs with a given extention then take it from there.  Also zxr250 is right about needing to send out the appropriate header to the browser before trying to print out any actual output so...
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now