pass all cgi parameters to an exe

Discussion in 'Perl Misc' started by D, Jul 22, 2003.

  1. D

    D Guest

    i want to pass all cgi parameters to an exe (cgi app) and run the executable
    and capture all of its output.

    use CGI;
    my $all_params;
    my $thing = `C:/Inetpub/scripts/webapp.exe $all_params`;
    print $thing;

    this gives me a web page that declares and error, wich is what i would
    expect, but this is good because when i pass it the right parameters i will
    get back htm and i can parse it easily. the problem is i want to
    impersonate what IIS would have passed if i did something like
    http://site/scripts/webapp.exe and i thing the CGI module would do this for
    me easily but dont know how.
    D, Jul 22, 2003
    #1
    1. Advertising

  2. D <> wrote:
    > i want to pass all cgi parameters to an exe (cgi app) and run the executable
    > and capture all of its output.



    I think you are saying that you want to run a program (webapp.exe)
    that was designed to run in the CGI environment from the command
    line instead?

    Why must you do that?

    Why not access the designed-for-CGI program in the environment
    it expects?


    > i want to
    > impersonate what IIS would have passed if i did something like
    > http://site/scripts/webapp.exe



    If you want to _impersonate_ what the web server does, then you'll
    need to setup the input to webapp.exe whereever it expects it.

    That is, you'll need to setup an env var or stdin depending on
    whether it is a GET or POST request.


    A much better solution would be to have the *real web server*
    do it's thing. You can invoke webapp.exe via a web server if
    you make the request using one of the LWP modules.


    See the Perl FAQ:

    How do I fetch an HTML file?

    How do I automate an HTML form submission?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 22, 2003
    #2
    1. Advertising

  3. D

    D Guest

    "Tad McClellan" <> wrote in message
    news:...
    > D <> wrote:
    > > i want to pass all cgi parameters to an exe (cgi app) and run the

    executable
    > > and capture all of its output.

    >
    >
    > I think you are saying that you want to run a program (webapp.exe)
    > that was designed to run in the CGI environment from the command
    > line instead?
    >
    > Why must you do that?
    >
    > Why not access the designed-for-CGI program in the environment
    > it expects?
    >
    >
    > > i want to
    > > impersonate what IIS would have passed if i did something like
    > > http://site/scripts/webapp.exe

    >
    >
    > If you want to _impersonate_ what the web server does, then you'll
    > need to setup the input to webapp.exe whereever it expects it.
    >
    > That is, you'll need to setup an env var or stdin depending on
    > whether it is a GET or POST request.
    >
    >
    > A much better solution would be to have the *real web server*
    > do it's thing. You can invoke webapp.exe via a web server if
    > you make the request using one of the LWP modules.
    >
    >
    > See the Perl FAQ:
    >
    > How do I fetch an HTML file?
    >
    > How do I automate an HTML form submission?
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas


    the thing is this executable is proprietary and i cannot get the source
    code, and it does some things that need to be logged. essentially if i can
    intercept the output of this exe, i can then parse the output and log what
    happened, lets pretend that it gives a page that cancels someones bank
    account. so the exe communicates with a mainframe and cancels a persons
    account then spits out an html page that says it confirmed the cancel and so
    on, i need to log that. the button that submits POSTS all the forms to this
    exe can be changed so that it calls my perlscript instead (there is a
    rudimentary html file the exe uses as a template). when you mentioned stdin,
    that sounded like the answer. but i wouldnt have a clue how to do that, i
    figure it must be simple, you take everything that was passed to the
    perlscript from the webserver, and then pass it to the exe, get the result
    and log it, then pass that same result with no modifications back out to the
    browser. i think
    D, Jul 23, 2003
    #3
  4. D

    D Guest

    "D" <> wrote in message
    news:iLaTa.107825$...
    > i want to pass all cgi parameters to an exe (cgi app) and run the

    executable
    > and capture all of its output.
    >
    > use CGI;
    > my $all_params;
    > my $thing = `C:/Inetpub/scripts/webapp.exe $all_params`;
    > print $thing;
    >
    > this gives me a web page that declares and error, wich is what i would
    > expect, but this is good because when i pass it the right parameters i

    will
    > get back htm and i can parse it easily. the problem is i want to
    > impersonate what IIS would have passed if i did something like
    > http://site/scripts/webapp.exe and i thing the CGI module would do this

    for
    > me easily but dont know how.


    heres one solution maybe not the best one

    my $q = new CGI;
    my $url_params;
    my @the_params = $q->param;
    foreach my $param_name (@the_params)
    {
    my $param_value = $q->param($param_name);
    $url_params = $url_params . $param_name . "=" . $param_value . "&";
    }
    my $ua = new LWP::UserAgent;
    print "Content-type: text/html\r\n\r\n";
    my $reg_url = "http://server/scripts/webapp.exe?$url_params";

    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;
    $ua->agent("$0/0.1 " . $ua->agent);
    my $req = HTTP::Request->new( GET => $reg_url );
    $req->header('Accept' => 'text/html');
    my $res = $ua->request($req);
    if ($res->is_success)
    {
    $thing = $res->content;
    if ($thing =~ /KEY TEXT/)
    {log_cancellation();} ##i can change or log the output of the exe
    print $thing;
    }
    else
    {print "Error: " . $res->status_line . "\n";}
    D, Jul 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Namratha Shah \(Nasha\)
    Replies:
    0
    Views:
    4,685
    Namratha Shah \(Nasha\)
    Nov 5, 2004
  2. Muzammil
    Replies:
    1
    Views:
    1,073
    red floyd
    Aug 28, 2008
  3. Scott Townsend
    Replies:
    0
    Views:
    259
    Scott Townsend
    Jan 29, 2004
  4. john.swilting
    Replies:
    0
    Views:
    93
    john.swilting
    Mar 21, 2007
  5. - Bob -
    Replies:
    2
    Views:
    136
    - Bob -
    Mar 23, 2007
Loading...

Share This Page