Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

retrieving varaibles from cgi

celeronpmceleronpm Posts: 2Member
I have a cgi script that returns, let's say, a word. I want to remotely run the cgi script from the a perl file, and then display the word. I know it's possible, beacuse I have done it in the past. I have forgotten how and I am stuck.
Here is how I would want to run the code from perl.

sub whatever {
my $word = 'require user/myscript.cgi';
print $word;
}
Using require runs the cgi file but it doesnt link the output to the variable. It only displays the cgi ouput while skipping the rest of my perl file. What is the correct way or writing the link?

Comments

  • JonathanJonathan Posts: 2,914Member
    : I have a cgi script that returns, let's say, a word. I want to
    : remotely run the cgi script from the a perl file, and then display
    : e word. I know it's possible, beacuse I have done it in the past. I
    : ve forgotten how and I am stuck.
    : Here is how I would want to run the code from perl.
    :
    : sub whatever {
    : my $word = 'require user/myscript.cgi';
    : print $word;
    : }
    : Using require runs the cgi file but it doesnt link the output to the
    : variable. It only displays the cgi ouput while skipping the rest of
    : my perl file. What is the correct way or writing the link?
    I can't believe what you've got there works at all because you're just assigning a literal value to $word, and not executing anything...

    Backticks may do it for you:-

    my $word = `user/myscript.cgi`;

    That will capture the output of myscript.cgi into $word. Any good? I don't know it's the most efficient way as it requires a new instance of perl to be started. OTOH, that may be a Good Thing as you won't end up with variables from each script conflicting etc.

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • celeronpmceleronpm Posts: 2Member
    : : I have a cgi script that returns, let's say, a word. I want to
    : : remotely run the cgi script from the a perl file, and then display
    : : e word. I know it's possible, beacuse I have done it in the past. I
    : : ve forgotten how and I am stuck.
    : : Here is how I would want to run the code from perl.
    : :
    : : sub whatever {
    : : my $word = 'require user/myscript.cgi';
    : : print $word;
    : : }
    : : Using require runs the cgi file but it doesnt link the output to the
    : : variable. It only displays the cgi ouput while skipping the rest of
    : : my perl file. What is the correct way or writing the link?
    : I can't believe what you've got there works at all because you're just assigning a literal value to $word, and not executing anything...
    :
    : Backticks may do it for you:-
    :
    : my $word = `user/myscript.cgi`;
    :
    : That will capture the output of myscript.cgi into $word. Any good? I don't know it's the most efficient way as it requires a new instance of perl to be started. OTOH, that may be a Good Thing as you won't end up with variables from each script conflicting etc.
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Thanks for the help but the problem still exists. It doesn't seem to capture the output of the cgi script. my $word = require 'user/myscript.cgi'; is the only thing that will work, and it will only output the cgi output without continuing the output of the perl.
  • JonathanJonathan Posts: 2,914Member
    : Thanks for the help but the problem still exists. It doesn't seem to
    : capture the output of the cgi script. my $word =
    : require 'user/myscript.cgi'; is the only thing that will work, and
    : it will only output the cgi output without continuing the output of
    : the perl.
    The require method won't work at all. require purely includes some code at runtime and runs it as if it's part of the current script. It doesn't return what the script outputted. If that script says exit, then the whole things will exit. All output just goes straight to STDOUT.

    That's why I suggested that you need to run the script seperately outside of your script using backticks like I showed you. I say you forget require. It's not going to work for you unless you somehow redirect STDOUT to some place you can capture data (doable, but probably not worth the hassle).

    Note if you're on Win32 you may need to do:-

    my $output = `perl path/to/script.cgi`;

    I doubt that would do any harm under Linux/UNIX OSes either.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.