What you're talking about is known in web development circles as CGI programming, and it's generally much easier to do in Perl than in C or most other languages. There are assorted ready-made modules available to make it even easier still. For example, you might want to look at CGI or CGI::Lite. As far as Apache, that's good news: Apache is generally very easy to work with. The first time I ever played around with CGI programming, I downloaded and installed Apache, configured it, wrote my Perl script, and had it working all in one afternoon. It wasn't the most elegant script ever (I was pretty new to Perl at the time), but it worked.

Here's what you need to know, then...

Here is a very minimal CGI script that you can use to test your setup to see that it's working:

#!C:\wherever\Perl.exe print "Content-type: text/html <html><head><title>test</title></head> <body><h1>It works.</h1></body></html> ";

update: Other monks' posts have made me look again at your request, and I think maybe you wanted to get the output from an external executable (written in C) and send _that_ to the user. This also is quite possible (maybe even easy, depending on how the executable takes its input). In the trivial case where the external program doesn't need any input but only generates output, this will work:

#!C:\wherever\Perl.exe open FOO, "C:\wherever\program.exe |"; # The | is a pipe; we're running program.exe and # reading its output from the FOO filehandle: print "Content-type: text/plain\n\n"; while (<FOO>) { print }

If the C script takes command-line arguments, that the user needs to specify, then you'll need to have an HTML form that lets the user specify this input, and your Perl script will take that input and massage it into command-line arguments for the external program. You can insert those arguments directly into the commandline, as in,

open FOO, "C:\wherever\program.exe @args |";

If the external program expects input in standard input, then post a reply saying so and we'll go into how to do that too.

It is also a good idea to make sure the program in question can't do anything destructive that you don't want, before turning loose a web interface straight to it. If possible, you should try to arrange for it to run as an unprivileged user, but I don't know enough about Windows 2000 to tell you how to do that.

If what the C program does is very simple, you may want to just rewrite it in Perl.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

In reply to Re: Can Perl do this...? by jonadab
in thread Can Perl do this...? by DJ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.