Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

need help to passing argument to executable and get return the result

by ashwani (Initiate)
on Aug 19, 2006 at 06:45 UTC ( #568313=perlquestion: print w/replies, xml ) Need Help??
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
when i pass a value in text box and press button then this cgi script should pass this textbox value to should accept that value and should prepare this
<greet>//here text box value//</greet>

and 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 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
  • Comment on need help to passing argument to executable and get return the result
  • Download Code

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 :)
    ## my $arguments = 'beep'; my $var = `perl $arguments`; print $var;
    ## my $var = shift @ARGV; $var = uc($var); print $var;
    If I do perl, I get the result BEEP, which means it's passing back and forth properly.
      Thanks TedPride it was really very helpful.
      can you solve one more thing?
      if there are four argument then how will handle it?
      Thanks again
        ted pride i used ur code it is working properly.Thanks
        but i got error when i pass both parameter but one is blank so this code could not handle that condition and i trapped in this.
        $output=' $param1 $param2'; where $param1=''; $param2=0;
        i'm not getting how can i handle it.
        my ($x,$y)=@argv;
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,"| $my_value") or ...... ; my @retvals = <IN> ; # or do it with a while(<IN>){} close IN ; 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 = ` $my_value`

    I think you see the poin!

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

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

        if i'm passing two arguments

      thanks LuCa...
      but i could not get how can i access the textbox value in as tedpride say.
      i said there is 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://568313]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-01-24 12:11 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (204 votes). Check out past polls.