How to call another program

D

David Grey

Sam said:
use LWP::Simple;

print "Content/type: text/html\n\n";
print "The perl.com website looks a little like this:<hr>\n";
my $result = get('http://www.perl.com');
print $result;
print "<hr>The perl.com website looked a little like that\n";

Of course I excluded simple things like error checking and valid specification
following output.

And this process the response from accessing a URL via some
kind of HTTP request to my script on domain.com how?

A grudgingly thanks.
 
J

Jim Cochrane

Jim said:
Alan J. Flavell wrote:

On Sun, 2 May 2004, David Grey wrote:

(in reply to A. Sinan Unur , and your carelessness with attributions
isn't helping your case:]

I'm not going to try what will not do what I want, I want
to run a script in a script, I saw no evidence what you posted
would do that.

Actually that's not as obvious as it seems. You obviously don't yet
understand what you are doing nor how to properly ask about what you
want - which is perfectly OK - we all have to start somewhere; it
would be to your advantage to explore all kinds of relevant building
blocks so that you could get a better feel for how they fit together,
after which, the answer to your problem will likely seem so obvious
that you won't need to ask about it.

Well I'm sure that is the case, but I am living in the real world
and need this done yesterday, I don't have time for theory
and a learning experience today, I need this fixed. And it is
a bit frustrating to get the answer, go look it up, when you know
they know the answer but wont tell you. (Not in a form that
comprehendable at my level of understanding.)

No offense intended, but with a situation like this, with a tight deadline,
although a newsgroup can often provide a timely solution, it's often best
to, if possible, pay a consultant.

I'm suppose to pay some $150. to get a one line code, I don't
think so. I knew this was going to be one of the answers,
you people must all be X gens and think this is helpful.

No, you're not supposed to do anything, particularly. I was attempting
to point out that from a practical viewpoint, in such a situation,
paying someone if sometimes the best solution. It's just a matter of weighing
the different factors - How urgent the problem is, how big your budget is,
etc. (If you're a one-person company, of course, such an expense can be a
big deal; with a larger company, it wouldn't be.)

I really did mean no offense intended - I was just trying to point out a
(IMO) practical reality, rather than to suggest that this is what you
should do. I don't really know your situation, so I'm not qualified to
really suggest anything.

I'm not a gen-X-er, by the way - much too old for that :)
At least you were nice in being snippy.

Well, I'd rather be snippy than snappy. (How's that for gibberish? :))
 
D

David Grey

John said:
No, I mean "What is really happening?". Until you address this
question, nobody can help you.

See below
OK, maybe I'm not understanding something. I thought you were putting
the URL into a browser, like IE or Mozilla or something. Are you
running a script from the command-line then?

I guess I can't help you unless you tell me if you're using a browser,
and if not, then what the heck are you using?


The customer will click on a button and there will be a URL to
the script on that site (below), this script needs to (run) process
the response from accessing a URL via some kind of HTTP
request to my script on the domain.com. I have been told to
use LWP and tried:

#!/usr/bin/perl

use warnings;
use strict;

use LWP::UserAgent;
use URI;

$ua = new LWP::UserAgent;
$uri = new URI('http://www.domain.com/temp.txt');
$localfile = 'temp.txt';

# This part just added .. start --------
$ua2 = new LWP::UserAgent;
$uri2 = new URI('http://www.domain.com/copyprog.pl');

my $request = HTTP::Request->new('GET', $uri2);
my $result = $ua2->request($request);
# sleep 10
# end .. of new part, that did not work ----------

# Create request with HTTP 1.1-style Range header
my $request = HTTP::Request->new('GET', $uri);

# Fetch it
my $result = $ua->request($request);

# Append the fetched data to the local file
open OUT,">>$localfile";
print OUT $result->content;
close OUT;


Which does not work. It does not activate the script on
domain.com sleep 10 gave me an 500 error.

Thanks
 
U

Uri Guttman

DG> Yes, it helps me understand it, but not do it.

you don't get it. YOU WERE TOLD HOW TO DO IT AND EXAMPLE CODE WAS
POSTED. you CHOSE TO IGNORE IT BECAUSE OF SOME FOOLISH REASONS.

i give up.

uri
 
U

Uri Guttman

DG> Well I'm sure that is the case, but I am living in the real world
DG> and need this done yesterday, I don't have time for theory
DG> and a learning experience today, I need this fixed. And it is
DG> a bit frustrating to get the answer, go look it up, when you know
DG> they know the answer but wont tell you. (Not in a form that
DG> comprehendable at my level of understanding.)

in what real world do you not HIRE A PROGRAMMER to do this job for you?
in the time you have wasted here, you could have posted to jobs.perl.org
and gotten someone to do this for $50. was that not worth the time?
you say you consult but don't ever expect me to hire someone with such a
poor sense of how to solve something. if you want to do it yourself,
learn some perl and web. if not, hire someone who can. sitting on the
fence must be fun for you.

uri
 
U

Uri Guttman

DG> And this process the response from accessing a URL via some
DG> kind of HTTP request to my script on domain.com how?

DID YOU READ MY POST? you claimed it was helpful. it DESCRIBED EXACTLY
WHAT sam wrote there. in fact sam could have written this code from my
description so i want my share of the fees we should charge you.

what more do you need? a bottle? someone to teach you basic coding and
comprehension? now why hasn't moronzilla stuck her snout into this
mess. it reeks of the classic web crap she always did. you deserve that
kind of help.

DG> A grudgingly thanks.

and more back at ya. you don't deserve any more help. you have gotten
$100's worth of work here for free and you spit on it.

uri
 
D

David Grey

Scott said:
The error was due to the missing semicolon. Do you test your scripts
locally before you post them? If not, you are going to be at this for a
long time before you get it working!

Well, I don't have perl on my PC, thanks for the help, did you
happen to see why the request to http://www.domain.com/copyprog.pl
did not work?
 
T

Tad McClellan

David Grey said:
but I am living in the real world
and need this done yesterday, I don't have time for theory
and a learning experience today, I need this fixed.


If you don't have time to learn it yourself, you might consider
hiring someone who has already taken the time to learn it.

http://jobs.perl.org
 
J

Joe Smith

David said:
That is not what I want to do (from what I can tell) I want to :

print "Location: http://www.domain.com/cgi-bin/copyprog.pl\n\n";

run this script before running the rest of the script. When I run the
above it goes off and does not run the rest of the script that this
is in.

Unless you are using frames or <img src>, the browser processes one URL
at a time. If the original request is to cgi-bin/part-1.pl, you've
got two choices:
1) Let part-1.pl go to completion, and output the Location at the end.
2) Output the Location at beginning of part-1.pl, but then you've got
the problem that part-1.pl will be prematurely terminated when
the browser closes the connect as it switches to copyprog.pl.

You could have part-1.pl output HTML that runs two CGIs in parallel.

<frameset rows="100%,*">
<frame src="/cgi-bin/part-2.pl">
<frame src="http://www.domain.com/cgi-bin/copyprog.pl">
</frameset>
<noframes>
<body><img src="/cgi-bin/part-2.pl" width=1 height=1">
<img src="http://www.domain.com/cgi-bin/copyprog.pl" width=1 height=1>
</body>
</noframes>

-Joe
 
A

Alien Resident

David said:
I have not a clue what you are saying in the first place,
I'm suppose to pay some $150. to get a one line code, I don't
think so.


It's interesting to see the effect interacting with fellow humans by means of the web has
on ones boldness. This "David Grey" character is an interesting study. Let's say that he
had started building a house for someone and he had no prior building experience, and now
he finds himself behind schedule and the housing code inspector is due to come the next
day. Would this "David Grey" go down to a construction site near by and during lunch start
telling these guys that they HAVE TO HELP HIM BECAUSE HE KNOWS THEY KNOW HOW TO FIX HIS
PROBLEM!!! If they didn't just kick his butt and send him home crying after the first time
he opened his mouth, they'd definitely do it after they did try to help him and he cried,
moaned and insulted them because he couldn't understand how they got the total square feet.

But really, for fear of a fat lip this "David Grey" probably wouldn't take that route.
Although he will do it online, for he has no fear of physical retaliation for it extremely
low level of social and ethical standards and or skills.

Ah, such is the world these days.

-AR
 
D

David Grey

Joe said:
Unless you are using frames or <img src>, the browser processes one URL
at a time. If the original request is to cgi-bin/part-1.pl, you've
got two choices:
1) Let part-1.pl go to completion, and output the Location at the end.
2) Output the Location at beginning of part-1.pl, but then you've got
the problem that part-1.pl will be prematurely terminated when
the browser closes the connect as it switches to copyprog.pl.

You could have part-1.pl output HTML that runs two CGIs in parallel.

<frameset rows="100%,*">
<frame src="/cgi-bin/part-2.pl">
<frame src="http://www.domain.com/cgi-bin/copyprog.pl">
</frameset>
<noframes>
<body><img src="/cgi-bin/part-2.pl" width=1 height=1">
<img src="http://www.domain.com/cgi-bin/copyprog.pl" width=1 height=1>
</body>
</noframes>

-Joe

Dude, that worked ! Thanks

After like 15 hours of trying to do it as the rest said, this works.
I don't use frames so I never even thought of that, I was think of

<META HTTP-equiv="Refresh" content="1;
URL=http://www.domain.com/cgi-bin/copyprog.pl">

But of course I could not figure out how to make it do two bounces.

Thanks again !
 
A

Alan J. Flavell

You could have part-1.pl output HTML that runs two CGIs in parallel.

<frameset rows="100%,*">
<frame src="/cgi-bin/part-2.pl">
<frame src="http://www.domain.com/cgi-bin/copyprog.pl">
</frameset>
<noframes>
<body><img src="/cgi-bin/part-2.pl" width=1 height=1">
<img src="http://www.domain.com/cgi-bin/copyprog.pl" width=1 height=1>
</body>
</noframes>

Was that wise? While it seems to have got the questioner off our
backs, I'd have to say that if it were to be presented as a solution
in a WWW group (which is where I suspect it would be more on-topic,
since there's almost no specifically Perl-language relevance here), it
would likely have been shot down in flames.

There's just too many imponderables being left to the client side
(who'd be perfectly entitled to disable frames and/or images if they
felt like it) for this to rate as a robust piece of web engineering,
I'm afraid.

Since the original poster still hasn't really told us what the
*underlying* problem is - beyond what we can deduce from the
description of a number of failed attempts at a solution - we don't
know whether such a shambolic edifice is going to represent a
tolerable kludge, or a life-threatening risk, or someting in between.

So "caveat implementor", or something like that.
 
J

Joe Smith

Alan said:
Was that wise? While it seems to have got the questioner off our
backs, I'd have to say that if it were to be presented as a solution
in a WWW group (which is where I suspect it would be more on-topic,
since there's almost no specifically Perl-language relevance here), it
would likely have been shot down in flames.

I did give it some thought, and decided that the expedient solution
would be worth it, if only to reduce flamage and allow other threads
of discussion to prosper.
There's just too many imponderables being left to the client side
(who'd be perfectly entitled to disable frames and/or images if they
felt like it) for this to rate as a robust piece of web engineering,
I'm afraid.

No frames: taken care of. Both no frames and no images: only the OP
would know if that would be a concern for his expected audience.
As for robustness, I expect the OP will eventually realize that he
had 95% of the solution with the script that use LWP twice.

I would have done it this way:

1) Output the HTTP and HTML headers immediately, to give the user
feedback. This would include sending <BR>, <HR>, <P></P>, or other
HTML tag that forces a line break, so that the browser will
render the partial page. (No <table> at this stage.)

2) Execute an LWP request inside the CGI, with a suitable timeout
being set. When the results come back, output more HTML, with
another line break.

3) Do post-processing. This could be fork()+exec(), system("... &"),
or just let the browser sit and wait for processing to complete.
[I've seen one CGI output <HR width="10%">(pause)<HR width="20%">,
etc as a pseudo progress bar.]

-Joe
 
A

Alan J. Flavell

No frames: taken care of.
conceded

Both no frames and no images: only the OP
would know if that would be a concern for his expected audience.

Right. I would have been more comfortable if the answer had made that
explicit, though.
As for robustness, I expect the OP will eventually realize that he
had 95% of the solution with the script that use LWP twice.

Food for thought...

all the best
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top