Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: running an executable from a cgi script

by serf (Chaplain)
on Feb 09, 2006 at 16:18 UTC ( #529120=note: print w/ replies, xml ) Need Help??


in reply to running an executable from a cgi script

Could you perhaps show us how you run it from the command line?

This piece of code doesn't seem to do much yet (is it meant to be pseudo code?)

Things to think about:

  • Are you trying to run the executable remotely from another machine via CGI? and also pick up the file from off the web? (because this is what your file starting with "http://" makes it look like. If you want to do that I'd probably look at something like LWP::Simple - which makes it very easy to slurp in a file off the web.

    (Or were you meaning to tell the CGI the path to a file sitting on the same server as itself? - which is what your question seems to indicate. If so you would only need to give it the local path to the file as far as the CGI program was concerned (or more securely the name of a file sitting in a predetermined directory on the server where the program *always* looked for its files.)

  • Your script starts off with use CGI; indicating that it is intended to be run as a CGI program itself - is that what you really mean? to run one CGI which calls another CGI? Perhaps you actually intend to run one CGI which executes a file locally (i.e. on the same server as the CGI script) instead? - if so, you wouldn't need to call it with "http://" - but would probably want to run it locally using open and a pipe like this:
  • # path to program my $prog = '/local/path/to/cgi-bin/executableprog'; open(PROG, "| $prog") || die "Can't run '$prog': $!\n"; print PROG "$file\n"; close(PROG);
  • Presumably where you have:
    my $pid = open PIPE, "-|";
    and then:
    exec PROG or die "Cannot open pipe to executableprog: $!";
    PIPE and PROG were meant to be talking about the same process?
  • What's the stuff for a fork for? you're probably better off not worrying about forking (which is a little complex) until you get the basics of reading and writing files and running programs mastered.


Comment on Re: running an executable from a cgi script
Select or Download Code
Re^2: running an executable from a cgi script
by Angharad (Pilgrim) on Feb 09, 2006 at 16:41 UTC
    Yes, PIPE and prog are meant to be talking about the same process. oh dear .. i have a lot to learn here.
    OK ... well eventually I would like this program to be run as a cgi itself yes. But I'm not going to be running another cgi from this script, its a C program. Everything is on the same server, so perhaps I could run them locally then.
    Thanks for the tips so far.
    As for how I would run the program on the command line normally .. well I would type in the name of the program to start .. and then a prompt comes up asking me for the text file to process.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://529120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-07-29 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls