Discussion Locked

PERL exec or system commands

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am using an apache web server on a linux OS.
I want to use the perl exec or system command to either call another html file or to call a real audio video file.

while I can use
exec(`ls>fileb` ); to place a directory listing in a text file, Iam unable to call an html page or a real audio file
what am I missing and what command syntax should I use to successfully call an html page or a real audio file

your answer must work to recieve points !

10 replies

by dietmar

Any exec has to return a correct header and the dat you want to show to stdout.
So provide a correct header for that type (html or real audia) and 'cat' the file you want to execute to it, e.g. `cat sample.html`.

by jim

not exactly a clear answer, considering exec calls a program but terminates the program it is calling from...while I can telnet in and run the script[using your suggestion] and it works fine, it doesn;t work while being called from a browser...nice attempt , but not even close to what I am looking for

by jim

not exactly a clear answer, considering exec calls a program but terminates the program it is calling from...while I can telnet in and run the script[using your suggestion] and it works fine, it doesn;t work while being called from a browser...nice attempt , but not even close to what I am looking for

by jonasbn

I'm not sure I understand your problem. BUT as the other answer states you should fill in a correct header:

The script called from the webserver must be a CGI script. Which means that it should return the string:

"Content-type: text/html" (followed by two newlines)

So if you want to return HTML from your script it should look like this:

#!/usr/bin/perl -w

print "Content-type: text/html\n\n";
system("ls>mydir");
open(FIN, "mydir")
while () {
print $_;
}
close(FIN);

So in order to call something else than an ascii text (HTML), you should provide the HTTP server with a header identifying what you a sending back.

If you can provide me with more data I might be able to help you out. I don't fully understand whatyou mean by calling. You can call executables, but results will always be either binary or ascii.

I hope this helps you on your way, please remember to be carefull when using system calls on your CGI script, if somebody 'tweaks' your scripts theymight be able to do damage to your system.

by jim

******* while I can use
exec(`ls>fileb` ); to place a directory listing in a text file, I am unable to call an html page or a real audio file
*********
just to recap, what I am wanting to do is call, start or begin a real audio file from the CGI program.
The cgi program will have no paramaters passed to it. The program uses a database to help determine which real audio file/html page it needs to call, start or begin. Calling a OS command such as LS or CAT is pretty much a no brainer.
What I need specifically is for someone to click on a link on a web page which will start the program I have AND have that program call, start or begin a real audio file/html page.

Please limit your answers to the exact code that would reside within a cgi program that would allow the Real Audio File/Html page. Again the code must work to recieve the points.

by shanghai sam

Hi Kelly here we go again!

Two scripts. First script lists file, second script 'streams'...

Script 1:

#!/usr/bin/perl -w

print "Content-type: text/html \n\n";
print qq[Irish Boy\n];

exit(0);

Script 2:

#!/usr/bin/perl -w

use strict;
use CGI qw(param);

my $mpeg = param('mpeg');

if ($mpeg) {
print STDERR "fetching mpeg file: $mpeg\n";
if (-e $mpeg) {
my $size = -s $mpeg;
open(FIN, "<$mpeg") or die "arg! cannot open file $!\n";
print "Content-Length: $size\nContent-Type: audio/mpeg\n\n";
while () {
print;
}
close(FIN);
}
} else {
print "Content-type: text/html\n\nAhhhh sweet silence...(damn error)";
}
exit(0);

Contact me for explanations and clarifications at jonasbn@wanadoo.dk

Jonas

by shanghai sam

If you need something that someone could click on a link on a web page which will start the program you have and have that program call, start or begin a real audio file/html page...

my suggestion is you put full path your cgi program path in hyperlink reference like this:

your_text_to_display

or you can make your cgi program executable when a page is load...

you need just to add following code to your html page...

but you need to rename your .html file to .shtml and your need to install SSI if you don't have it in your server...

This discussion is closed to new replies.