http://www.perlmonks.org?node_id=568313

ashwani has asked for the wisdom of the Perl Monks concerning the following question:

hi monks,
i just started learning perl and i'm trying to make an application. and i'm stuck to proceed.
well my requirement is
a simple cgi script having a html page contain a text box and button.
there is one more application hello.pl
when i pass a value in text box and press button then this cgi script should pass this textbox value to hello.pl
hello.pl should accept that value and should prepare this
<greet>//here text box value//</greet>

and hello.pl should return this to cgi script which should show that
text box ,button and that return value below the button.
if i made executable of hello.pl using pdk
then i'm stuck at how to pass that value to hello.exe and
how can i get that return value in cgi and can proceed.
i need to done it.
Thanks in Advance

Replies are listed 'Best First'.
Re: need help to passing argument to executable and get return the result
by TedPride (Priest) on Aug 19, 2006 at 07:35 UTC
    You can call an executable installed on your system by using `script path`, and you can pass it a value by doing `script path arguments`. The script (if it's Perl) can then access these arguments the regular way, through @ARGV, and print a result, and you should be able to access the result if you did $var = `script path arguments`. I'll go test this now and see if my memory works properly :)
    ## print.pl my $arguments = 'beep'; my $var = `perl process.pl $arguments`; print $var;
    ## process.pl my $var = shift @ARGV; $var = uc($var); print $var;
    If I do perl print.pl, I get the result BEEP, which means it's passing back and forth properly.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: need help to passing argument to executable and get return the result
by jeanluca (Deacon) on Aug 19, 2006 at 07:55 UTC
    You can do it like
    open (IN,"| hellop.pl $my_value") or ...... ; my @retvals = <IN> ; # or do it with a while(<IN>){} close IN ;
    hello.pl can access the value via $ARGV[0]

    But be careful with processing user input! For example, what if $my_value contains '10 | rm -rf /' ( maybe the '|' should be a ';', I don't know, but I'm not a hacker)
    Than you can as well do @retvals = `hello.pl $my_value`

    I think you see the poin!

    LuCa
      see the CGI manual, the example are really good!!

      LuCa
        Thanks luca..
        now tell me can i do this
        my $q=$ARGV[0]; my $offset=$ARGV[1];

        if i'm passing two arguments

        Thanks
      thanks LuCa...
      but i could not get how can i access the textbox value in print.pl as tedpride say.
      i said there is print.pl or print.cgi having html code and showing textbox so how will this print.cgi get that textbox value.
      ted pride give hardcode value.
      if you know cgi->param('q') i need to know about that.
      thanks