473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Perl Open having problem when called from web.

We have two Perl script that use the open command to read an encrypted file. We just changed from gzip to gpg. One script works fine. The other is called from the web and fails on the open.

Both run on UNIX hosts running SunOS 5.9 and Perl 5.8.8.

To debug, I scaled down the problem script to something called testread4.pl. When I run it from the UNIX command prompt, it works fine. It opens the encrypted file and returns 10 line of output. When I call it from the webpage, it shows nothing in the browser. Checking the error_log file, it says:

gpg: cannot open `/dev/tty': No such device or address

It seems like from the web, its not getting all the UNIX environment variables and doesn't recognize /dev/tty.

The code is below:

http://ourhost:8000/cgi-bin/test4.cgi

cat test4.cgi

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/ksh
  2. . /home/apache1/.profile
  3. ./testread4.pl
  4.  
cat testread4.pl
Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl -w
  2.  
  3. $gpgPassFile = 'password';
  4. $fileWithPath= 'test.gpg';
  5.  
  6. $dataMax=10;
  7.  
  8. print "Start of file read\n";
  9.  
  10.         open(FILE, "gpg --passphrase-file $gpgPassFile --decrypt $fileWithPath | " ) ||
  11.              die("Unable to open $fileWithPath with gpg!");
  12.  
  13.         $x=0;
  14.  
  15.         while (<FILE>) {
  16.                 print "<tt> $_\n";
  17.                 if ($x >= $dataMax) {
  18.                     last;
  19.                 }
  20.         }
  21.         close(FILE);
  22.  
  23. print "End of file read\n";
  24.  
Any ideas?
Sep 17 '07 #1
4 2274
KevinADC
4,059 Expert 2GB
change this:

die("Unable to open $fileWithPath with gpg!");

to:

die("Unable to open $fileWithPath with gpg!: $!");

and you should get a better error description. Probably "permission denied" or "can't find file"

You might try a full path to pgp:

'/usr/bin/gpg --passphrase-file $gpgPassFile --decrypt $fileWithPath |'

or whatever the path is.
Sep 17 '07 #2
Made the changes you suggested. What's interesting is that it's not dying. I put some debug msgs before and after the open. It makes it past the open but it outputs nothing except the debug msgs.
Sep 17 '07 #3
KevinADC
4,059 Expert 2GB
I'm not sure what the problem is then. Can you run the perl script directly instead of uing ksh?
Sep 17 '07 #4
Solved it. Did a google for the error and found that others had encountered it as well. If I add the option --no-tty to the gpg command and add 2>/dev/null to the end, the former gets rid of the /dev/tty error while the latter gets rid of any error messages that the gpg generates.

Thanks for all the help!
Sep 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
10
by: Hendry Taylor | last post by:
I wrote a perl script and tested it on windows and it works fine. I then moved it onto a solaris machine and now it says that there is a syntax error with the following line of code: $user1 =...
0
by: brakesh | last post by:
Hi, I am trying to call a perl program (that connects a webserver database) from a php program via a webbrowser. For example : http://development.noaa.gov/test_exec.php?dataid=8313. The...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.