alright... heres my solution. I don't think it was the perl part that was so hard neccessarilly but there's a lot of weird/cool things you can do using ajax/dhtml. You should just be able to put these files in the same directory... and assuming your apache is ready to go, this should work.

if you have problems with this or need more help, let me know. i was very interested in this topic when you first made it... hope this helps. i hate to post so much JS on these forums... but here goes...



code.cgi
#!/usr/bin/perl use CGI; use strict; #getting code... my $cgi = new CGI; my $code = $cgi->param('code'); #making a temp file for the code open(CPP, ">code.cpp"); print CPP $code; close(CPP); #compiling file with output to file system("g++ -c code.cpp >& output.txt"); #HTTP headers print "Content-type: text/html\n"; print "\n"; #printing output file to response header open(OUTPUT, "<output.txt"); while(<OUTPUT>) { print $_ . "<BR>"; }


code.html
<HTML> <HEAD> <SCRIPT type="text/javascript" language="JavaScript"> //request object var req; function load_code(code) { //url and div var url="code.cgi"; var results_div = document.getElementById('results'); results_div.innerHTML = 'compiling...'; // code for Mozilla, etc. if (window.XMLHttpRequest) { req=new XMLHttpRequest(); req.onreadystatechange=reqChange; } //code for IE else if (window.ActiveXObject) { req=new ActiveXObject("Microsoft.XMLHTTP"); } //otherwise an error else { alert('unable to create xmlhttprequest object'); } //using post method (allows for 2000+ chars) if(req) { req.open("POST",url,true); req.setRequestHeader('Content-Type', 'application/x-www-form-url +encoded charset=UTF-8'); req.send("code=" + escape(code) + '\n'); } } //function called after perl script returns function reqChange() { // if xmlhttp shows "loaded" if (req.readyState==4) { // if "OK" if (req.status==200) { //getting div and the response var result_div = document.getElementById('results'); var response = req.responseText; //no response... no errors! if(response == "") { result_div.innerHTML = "There were no errors"; } //otherwise output errors else { result_div.innerHTML = response; } } //problem getting data... else { alert("Problem retrieving data") } } } </SCRIPT> <TITLE>Compiler Test</TITLE> </HEAD> <BODY> <TABLE width="100%" border=0> <TR> <TD width="50%"> <FORM name="compiler_form"> <TEXTAREA name="code" rows="30" cols="50"></TEXTAREA><b +r> <INPUT type="button" value="Compile" onClick='load_code +(this.form.code.value)'> </FORM> </TD> <TD width="50%"> <DIV id="results">Results</DIV> </TD> </TR> </TABLE> </BODY> </HTML>

In reply to Re: Accessing a C++ compiler through a CGI script by ickyb0d
in thread Accessing a C++ compiler through a CGI script by Spidy

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.