Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

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 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

Comment on need help to passing argument to executable and get return the result
Download Code
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.
      Thanks TedPride it was really very helpful.
      can you solve one more thing?
      if there are four argument then how will process.pl 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='xyz.pl $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,"| 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
      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
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://568313]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-04-16 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (423 votes), past polls