Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Does recursive call able to print in same page as main call

Reply
Thread Tools

Does recursive call able to print in same page as main call

 
 
Yohan N. Leder
Guest
Posts: n/a
 
      07-01-2006
I'm trying to do a differenciated recursive call (using command line
argument) print to same STDOUT than the one used during main first call.

#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
else{print "<p>main call</p>";}
exit 0;

or

#!/usr/bin/perl -w
use strict;
if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
else{print "Content-type: text/html\n\n<p>main call</p>";}
exit 0;

Both show "main call" in browser, but nothing about "recursive call with
cmdline argument".

How to do ?
 
Reply With Quote
 
 
 
 
David Squire
Guest
Posts: n/a
 
      07-01-2006
Yohan N. Leder wrote:
> I'm trying to do a differenciated recursive call (using command line
> argument) print to same STDOUT than the one used during main first call.
>
> #!/usr/bin/perl -w
> use strict;
> print "Content-type: text/html\n\n";
> if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
> else{print "<p>main call</p>";}
> exit 0;
>
> or
>
> #!/usr/bin/perl -w
> use strict;
> if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
> else{print "Content-type: text/html\n\n<p>main call</p>";}
> exit 0;
>
> Both show "main call" in browser, but nothing about "recursive call with
> cmdline argument".


I'm not at all sure what you are trying to do here, but it looks as if
you mean that you want your CGI script to call itself, while printing
its output to the browser. How are you doing the recursive call? Via a
call to system? How are you capturing and printing the output? Where are
the command line arguments getting set?

These scripts to not provide enough information to work out what you are
trying to do. There is no recursive call to a subroutine (the more
common sense of "recursive call"), nor is there any CGI redirect or
system call.

DS
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-01-2006
Yohan N Leder <(E-Mail Removed)> wrote:

> I'm trying to do a differenciated recursive call (using command line
> argument) print to same STDOUT than the one used during main first call.



You don't show any recursion, so we can't help you with the recursion.


> #!/usr/bin/perl -w
> use strict;
> print "Content-type: text/html\n\n";
> if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}



> How to do ?



You can't in a CGI program.

CGI programs take input either in an environment variable, or from
stdin, there is no "command line" for programs run in a CGI environment.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-01-2006
Yohan N. Leder wrote:
> I'm trying to do a differenciated recursive call (using command line
> argument) print to same STDOUT than the one used during main first call.
>
> #!/usr/bin/perl -w
> use strict;
> print "Content-type: text/html\n\n";
> if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
> else{print "<p>main call</p>";}
> exit 0;
>
> or
>
> #!/usr/bin/perl -w
> use strict;
> if ($#ARGV >= 0){print "<p>recursive call with cmdline argument</p>";}
> else{print "Content-type: text/html\n\n<p>main call</p>";}
> exit 0;
>
> Both show "main call" in browser, but nothing about "recursive call with
> cmdline argument".
>
> How to do ?


Let me guess: Are you possibly trying to test whether a query string was
appended to the URL when the script was invoked via a browser?

if ( $ENV{QUERY_STRING} ) { print ...

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Yohan N. Leder
Guest
Posts: n/a
 
      07-01-2006
In article <e85nq4$jf0$(E-Mail Removed)>,
(E-Mail Removed) says...
> I'm not at all sure what you are trying to do here, but it looks as if
> you mean that you want your CGI script to call itself, while printing
> its output to the browser. How are you doing the recursive call?
>


Oops, in my precipitation to ask for help, I written a totaly stupid
piece of test code. Sorry, here is a one closer to the real subject :

#!/usr/bin/perl -w
use strict;
if ($#ARGV >= 0){
print "<p>recursive call with cmdline argument</p>";}
else
{
use Config;
use Win32:rocess;
my $proc;
print "Content-type: text/html\n\n<p>main call</p>";
Win32:rocess::Create($proc, $Config::Config{perlpath},
"\"$Config::Config{perlpath}\" \"$0\" arg",
0, &Win32:rocess:ETACHED_PROCESS, ".")
|| die Win32::FormatMessage(Win32::GetLastError());
}

exit 0;


And, I never see the "<p>recursive call with cmdline argument</p>" in
browser.
 
Reply With Quote
 
Yohan N. Leder
Guest
Posts: n/a
 
      07-01-2006
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> You can't in a CGI program.
>
> CGI programs take input either in an environment variable, or from
> stdin, there is no "command line" for programs run in a CGI environment.
>


Sory for the first test code which was written too quickly : don't take
care about it. The real one is this one :

#!/usr/bin/perl -w
use strict;
if ($#ARGV >= 0){
print "<p>recursive call with cmdline argument</p>";}
else
{
use Config;
use Win32:rocess;
my $proc;
print "Content-type: text/html\n\n<p>main call</p>";
Win32:rocess::Create($proc, $Config::Config{perlpath},
"\"$Config::Config{perlpath}\" \"$0\" arg",
0, &Win32:rocess:ETACHED_PROCESS, ".")
|| die Win32::FormatMessage(Win32::GetLastError());
}

exit 0;

But, reading you, I'm wondering if it's really valid to do this second
process, calling the script through a command line ?
 
Reply With Quote
 
Yohan N. Leder
Guest
Posts: n/a
 
      07-01-2006
In article <(E-Mail Removed)>, (E-Mail Removed) says...
> Let me guess: Are you possibly trying to test whether a query string was
> appended to the URL when the script was invoked via a browser?
>
> if ( $ENV{QUERY_STRING} ) { print ...
>


In fact, not, since my way is simply to replace fork (which bugs in Win
with ActivePerl 5.8. with something which is right under Windows. So,
I'm going through Win32:rocess and a command line call, like this
(forgot the first inaccurate test code) :

#!/usr/bin/perl -w
use strict;
if ($#ARGV >= 0){
print "<p>recursive call with cmdline argument</p>";}
else
{
use Config;
use Win32:rocess;
my $proc;
print "Content-type: text/html\n\n<p>main call</p>";
Win32:rocess::Create($proc, $Config::Config{perlpath},
"\"$Config::Config{perlpath}\" \"$0\" arg",
0, &Win32:rocess:ETACHED_PROCESS, ".")
|| die Win32::FormatMessage(Win32::GetLastError());
}

exit 0;
 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      07-01-2006
Yohan N. Leder wrote:
> In article <e85nq4$jf0$(E-Mail Removed)>,
> (E-Mail Removed) says...
>> I'm not at all sure what you are trying to do here, but it looks as if
>> you mean that you want your CGI script to call itself, while printing
>> its output to the browser. How are you doing the recursive call?
>>

>
> Oops, in my precipitation to ask for help, I written a totaly stupid
> piece of test code. Sorry, here is a one closer to the real subject :
>
> #!/usr/bin/perl -w
> use strict;
> if ($#ARGV >= 0){
> print "<p>recursive call with cmdline argument</p>";}
> else
> {
> use Config;
> use Win32:rocess;
> my $proc;
> print "Content-type: text/html\n\n<p>main call</p>";
> Win32:rocess::Create($proc, $Config::Config{perlpath},
> "\"$Config::Config{perlpath}\" \"$0\" arg",
> 0, &Win32:rocess:ETACHED_PROCESS, ".")
> || die Win32::FormatMessage(Win32::GetLastError());
> }
>
> exit 0;
>
>
> And, I never see the "<p>recursive call with cmdline argument</p>" in
> browser.


This is a bad idea. The CGI environment is complicated enough. This
forces your script have to have to deal with two, rather different,
environments. You should make the process you call a completely
different script.

But if you're wedded to the idea of making a recursive call, I advise
that you distinguish the recursive invocation using the QUERY_STRING
environment variable (to be consistent with CGI).

Also, before you do recursive invocations using Win32:rocess::Create,
make sure that you can do simple, non-recursive invocations of other
scripts and programs using Win32:rocess::Create.

Again, recursion this way is a bad idea. There is a 99% chance that
creating a separate process for each recursive "call" is not necessary
for your application. Just create one big subroutine and call it
recursively like so:

#!/usr/bin/perl

use strict;
use warnings;

sub bigsub;
bigsub;

sub bigsub {
my $job = shift;
if (! $job) {
print "Content-Type: text/html\n\n";
print "<title> Recursive Call </title>\n";
print "<p> main call </p>\n";
print bigsub($_) for qw(Sailor Construction-Worker
Police-Man Indian);
} else {
return "<p> I'm a $job. </p>\n";
}
}

 
Reply With Quote
 
Yohan N. Leder
Guest
Posts: n/a
 
      07-01-2006
In article <LBwpg.999$(E-Mail Removed) t>,
(E-Mail Removed) says...
> Again, recursion this way is a bad idea. There is a 99% chance that
> creating a separate process for each recursive "call" is not necessary
> for your application. Just create one big subroutine and call it
> recursively like so:
>


Yes, but originally, I needed to fork. Unfortunately, it bug when script
is in taint mode under ActivePerl 5.8.8 (known bug). Then, I did it
going through threads with async : unfortunatly again, it's subject to
same bug : perl crash ! So, I've finally tried using Win32:rocess...
And here I am.

Well, so, since you told me to don't use command line call and knowing
it's the way Win32:rocess:Create works : how to do ?

How to launch asynchronously a call to a sub in the same script knowing
I can't fork() nor threads's async{} ?
 
Reply With Quote
 
Eric R. Meyers
Guest
Posts: n/a
 
      07-01-2006
Yohan N. Leder wrote:

> Yes, but originally, I needed to fork. Unfortunately, it bug when script
> is in taint mode under ActivePerl 5.8.8 (known bug). Then, I did it
> going through threads with async : unfortunatly again, it's subject to
> same bug : perl crash ! So, I've finally tried using Win32:rocess...
> And here I am.
>
> Well, so, since you told me to don't use command line call and knowing
> it's the way Win32:rocess:Create works : how to do ?
>
> How to launch asynchronously a call to a sub in the same script knowing
> I can't fork() nor threads's async{} ?


One simple redirection may be a possible solution, but I don't think that
anyone quite knows yet what you where trying to do in the first place,
before you encountered the bug and started heading in this direction.

Please provide some details, or an example, of your CGI program's original
purpose, the CGI environment, the calls that need to be made and the
arguments that need to be passed along to process the data.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to display color in excel not able to display color in excel using xml sed_y XML 0 02-15-2012 09:46 PM
how #define a main() function and call our own main function? ravi C Programming 28 09-26-2007 01:33 AM
Q: recursive call to main, termination of program Seong-Kook Shin C Programming 5 01-27-2005 12:00 PM
Change main window href from IE search panel, after user has left my main page? Robert Oschler Javascript 1 10-12-2004 08:34 PM



Advertisments