javascript - How can I pass information into perl script from web? -


i want call perl script using java script, , pass java script variable? script written else. want script on text output results on website. problem script requires file input.

the perl script has following usage

latexindent.pl [options] [file][.tex] 

i want pass in text box when call script, , return commands printed console javascript function.

function ajax_info() {     $.ajax({         url:       "latexindent.pl",         cache:     false,         datatype:  "text",         data:      { mode: 'this text!' },         success:   function(result) { ajax_info_result(result); }     }); }   function ajax_info_result(result) {     var text   = "the server says: <b>" + result + "</b>";     $('#info').html(text); } 

you mentioned cgi tag assume aren't using node.js in case @ somthing along lines of

var exec = require('child_process').exec; var cmd = 'prince -v builds/pdf/book.html -o builds/pdf/book.pdf';  exec(cmd, function(error, stdout, stderr) { // command output in stdout }); 

so assuming wish run perl on server cgi executed web server dinesh pointed out have 2 options.

options 1:

edit file act cgi , make accessible through web server configuring cgi handlers etc.

basically need to: include cgi.pm, extract posted parameters , use these in place of file contents. along these lines should started.

#!/usr/bin/perl  use strict; use warnings; use cgi::carp qw(fatalstobrowser); use json;  $cgi = cgi::carp->new(); $data = from_json( $cgi->param('mode') ); ## prob need tweak   ## continue processing using $data instead of file content. 

open 2: create perl cgi or configure web server handle request , execute existing script.

use similar code execute using system(), exec or `` approaches. sure read on security issues , differences between approaches of these calls regard capturing output , possibility of injection security issues.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -