How to call another program

D

David Grey

John said:
OK, I'll bite.

When you dlksj a script, what's happening?

One of two things, if I put in:

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

it go on its merry way and runs the script on domain.com and
the rest of the script is ignored, if I take it out it runs only
the script, I'm fickled and want it to do both. Run both
scripts, the one on domain.com first and wait until it is done.
Is that not forking() ? And everyone is now saying no it is not
forking.


You're using a web browser
of some sort to request a file from a web server.

Not that I know of, I put in the URL to the script and it
does whatever voo doo it do.

The server realizes
that it isn't a .gif or an .html file, but a script, so it runs the
script, and the output is returned to you and displayed by your browser.

Only if there is an error. It is all supposed to be done behind the
scene, they click on a URL and it runs both scripts (well that is
what I want).
The trick is that that script can, in turn, act like its own little web
browser. The tools to have it do that are in Perl's LWP (libwww-perl).

Yeah I have that in there to get a file after the script I want
to run, runs. But that is in the continued part, I just need to
run the script on the domain.com first. (That part is working
fine, but it is not running the scritpt that makes the file in the
first place.)
Here's a script that retreives the front pages from Yahoo! and Google,
and prints the output:

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $yahoo = get("http://www.yahoo.com/");
my $google = get("http://www.google.com/");
print $yahoo, $google;

That's how you can dlksj your script that's on some other server, but
not have your browser get stuck there.



Yeah, but that is not running a script on google. I got this
part, I need to run (dlksj) a script.

I thank you, very much anyway.
 
J

Jim Cochrane

This string is normally inserted by your newsreader. Why did you change my
last name?



No, I do not. But I don't like it when Tony posts a nice explanation and
you call it 'gibberish'.

People posting to this group for help (and, for that matter, to almost all
technical groups) need to realize that they are asking for free consulting
services. (Answering a, possibily difficult, programming-related question
is consulting.) Like many groups, there are knowledgeable people willing
to provide those services; but those asking for help should keep in mind
that the service is being provided, out of generosity, for no charge, and
that some patience and willingness to do one's own homework is often
required in order to benefit from these services. Sometimes it can seem
that people are being abusive (and sometimes that is actually the case),
but if one realizes that people are providing these services for free, one
may be more willing to not take the percieved abuse personally and will
more likely benefit from the resulting interaction.

And remember, there is no contract in this forum - If you don't get your
question answered, you are not justified in complaining to the BBB (or
whereerver). But if you have patience and appreciate the generosity of
those who respond to your question, you are more likely to obtain a
satisfactory result in the end.
 
D

David Grey

Tony said:
You are *not* running a "script in a script".


No, you want to process the response from accessing a URL via
some kind of HTTP request, probably GET.

This is your stumbling block. You are conflating accessing a
URL with the particular language in which you happened to code
the underlying implementation of that URL.

Or not in German, you want to connect to a webserver and
access something on that server. (The something happens to be
implemented as a perl program. That program outputs
something.)

I actually understood that part, :) I don't need the output,
because the output is a file that is made on domain.com
It is called later and I have that worked out, I just need to
(I guess as you said GET it) but then I need to make sure
it finishes making the file before continuing, is that not
forking()?

You want to collect what was output and then do
something else.


Not directly, not at that point, I just want to (your german)
"process the response from accessing a URL via some kind
of HTTP request" but it needs to wait like 10 seconds to
make sure it has made the file before continuing the script.


thanks
 
T

Tony Curtis

I actually understood that part, :) I don't need the
Leiwand!

output, because the output is a file that is made on
domain.com It is called later and I have that worked out, I
just need to (I guess as you said GET it) but then I need to
make sure it finishes making the file before continuing, is
that not forking()?

It is quasi-analogous to forking. Doing a redirect is
quasi-analogous to an exec(). But different to the point that
it isn't really helpful to pursue the analogy.
Not directly, not at that point, I just want to (your
german) "process the response from accessing a URL via some
kind of HTTP request" but it needs to wait like 10 seconds
to make sure it has made the file before continuing the
script.

So it's asynchronous at the remote end and you have no
callback or notification method? All bets are off.

If you really don't care what comes back from the request,
just do a "get" from LWP::Simple and discard the result. Make
sure the request worked though, and handle failure gracefully.
(Put in a sleep if that's the only way to ensure no race
hazards.)
 
D

David Grey

A. Sinan Unur said:
This string is normally inserted by your newsreader. Why did you change my
last name?

I did not, unless it was by accident. I have big fingers and a
little lap top.
No, I do not. But I don't like it when Tony posts a nice explanation and
you call it 'gibberish'.

If I don't understand it, it is gibberish, if my ignorance offends
you pluck something out.

How do you find the courage to leave home everyday?


HTTP does not work that way. What you have is a resource on another web
server. Requesting that resource results in a Perl CGI script being
executed on that server. When you do a redirect, you take your script out
of the picture. Kind of like setting up a blind date as opposed to going on
a double date.

If you are not interested in the actual content of the resource on the
other server, then you should be able to get away with using the head
function in LWP::Simple rather than get.

Damn that had to hurt, you were actually constructive there :)

And on top of that I understood what you said.
No you don't.

I know you are, but what am I.


Thanks
 
D

David Grey

Tony said:

Sie sind nett gewesen
It is quasi-analogous to forking. Doing a redirect is
quasi-analogous to an exec(). But different to the point that
it isn't really helpful to pursue the analogy.


So it's asynchronous at the remote end and you have no
callback or notification method? All bets are off.

Yeah that's about the size of it, I guess.
If you really don't care what comes back from the request,
just do a "get" from LWP::Simple and discard the result. Make
sure the request worked though, and handle failure gracefully.
(Put in a sleep if that's the only way to ensure no race
hazards.)


I tried:

sleep 10

and it gave me an 500 error, I took it out and no errors and
no success. Does "sleep 10" need a "use" file or is this the
wrong useage? This is what I have:

#!/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 ----------

# 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;
 
D

David Grey

Jim said:
People posting to this group for help (and, for that matter, to almost all
technical groups) need to realize that they are asking for free consulting
services. (Answering a, possibily difficult, programming-related question
is consulting.) Like many groups, there are knowledgeable people willing
to provide those services; but those asking for help should keep in mind
that the service is being provided, out of generosity, for no charge, and
that some patience and willingness to do one's own homework is often
required in order to benefit from these services. Sometimes it can seem
that people are being abusive (and sometimes that is actually the case),
but if one realizes that people are providing these services for free, one
may be more willing to not take the percieved abuse personally and will
more likely benefit from the resulting interaction.

And remember, there is no contract in this forum - If you don't get your
question answered, you are not justified in complaining to the BBB (or
whereerver). But if you have patience and appreciate the generosity of
those who respond to your question, you are more likely to obtain a
satisfactory result in the end.

Well I agree with what you say, and I am a consultant at times,
but if I know the answer and I am in a group I know the information
is given freely and try to give a answer that is not of the form go
look it up for yourself (with an implied lazy sod, ignorant twit).
If I know how to solve the problem and I have a program I
can copy and past that will do it with a little modification, I just
give it. Programming is mostly learned by doing it, but you have
to know how to do it in the first place, and that takes examples,
not use Perldoc -f sample whatever that is. If you don't know
what that is, it is no help. I don't have perl on my PC computer.
 
A

A. Sinan Unur

David Grey said:
Tony Curtis wrote:

Please quote properly.
Yeah that's about the size of it, I guess.



I tried:

sleep 10

and it gave me an 500 error, I took it out and no errors and
no success. Does "sleep 10" need a "use" file or is this the
wrong useage? This is what I have:

#!/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 ----------

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

Hmmmmm ...

C:\Home> perl -c t3
"my" variable $request masks earlier declaration in same scope at t3 line
23.
"my" variable $result masks earlier declaration in same scope at t3 line
26.
Global symbol "$ua" requires explicit package name at t3 line 9.
Global symbol "$uri" requires explicit package name at t3 line 10.
Global symbol "$localfile" requires explicit package name at t3 line 11.
Global symbol "$ua2" requires explicit package name at t3 line 14.
Global symbol "$uri2" requires explicit package name at t3 line 15.
Global symbol "$uri2" requires explicit package name at t3 line 17.
Global symbol "$ua2" requires explicit package name at t3 line 18.
Global symbol "$uri" requires explicit package name at t3 line 23.
Global symbol "$ua" requires explicit package name at t3 line 26.
Global symbol "$localfile" requires explicit package name at t3 line 29.
t3 had compilation errors.
 
C

Chris Mattern

David said:
If I don't understand it, it is gibberish,

An attitude that guarantees that you will never learn anything.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
A

A. Sinan Unur

David Grey said:
If you don't know what that is, it is no help. I don't have perl
on my PC computer.

Why not? Seriously, it does not take much to install Apache and ActiveState
Perl. That way, you can try things out much more easily.
 
D

David Grey

Alan said:
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.)
You don't seem to have the remotest clue what kind of impression
you're making by this kind of public exhibition. As such, my own
interim reaction is that you probably can't be helped. But I'll give
you the benefit of the doubt before you go into the killfile, and the
answer might just be helpful to someone else.

Well by this time I figured all I was going to get was more
go look it up you lead filled brained retard and figured I had
nothing left to lose.
Not on the basis of your own evidence, no. You want to invoke a
remote URL which happens to have a script behind it, while retaining
control of the situation so that you can return the result. The
answer to that is LWP.

I tried GET and HEAD and it did not work, do you have a
short example?
You don't know how to ask the question yet; that's OK - we all have to
make a start somewhere - but I'd say, on the basis of the most
plausible interpretation of what you want, is that the answer is LWP.


It would be the best thing if so, I already know a bit about that,
but still have not got anything that worked. But not getting any
errors is welcomed as well.

Thanks
 
S

Sam Holden

Well I agree with what you say, and I am a consultant at times,
but if I know the answer and I am in a group I know the information
is given freely and try to give a answer that is not of the form go
look it up for yourself (with an implied lazy sod, ignorant twit).

Whereas people who actually want others to learn things show them how
to find out. Give a man a fish, teach a man to fish, yada yada.

This is not a group working on a project, this is usenet you get
the answers you get. If you show just a hint of motivation to actually
learn something you get much better answers. If you don't you get
ignored.

In fact some of the answers to the original post have been very
good indeed. Pointing out exactly the terminology/understanding
problems and providing complete answers to the problem.
If I know how to solve the problem and I have a program I
can copy and past that will do it with a little modification, I just
give it. Programming is mostly learned by doing it, but you have
to know how to do it in the first place, and that takes examples,
not use Perldoc -f sample whatever that is. If you don't know
what that is, it is no help. I don't have perl on my PC computer.

Do we have to explain how to turn the computer on as well? Or
can we assume you can work that much out yourself.

If we don't then why do we have to explain how to read documentation
on your particular flavour of computer?

This is not a suitable forum for learning the basic first steps of
Perl programming. There are books for that. There are courses for that.
There are tutorials (or varying quality) on the web for that.

If you haven't heard of something that is mentioned (mind you a few pages
down) in the main perl documention (man perl - or for people who can't be
bothered looking up what man means,
Start menu->Programs->ActiveState Perl->Documentation or something
like that...) then you haven't bothered spending two minutes searching
yourself before deciding that your time is far more valuable than the
time of thousands of others who obviously have nothing better to do
then solve your problems for you.
 
D

David Grey

Uri said:
wow. all i can say is wow. what more do we need to do to get you to
understand what is happening and why your understanding of it is so
skewed.

let me try. i need a good challenge.

Into S & M too :)
ok, when you request web page (be it a file or dynamic like a cgi) you
make a connection to that web server and it does the work for you. you
don't care about what script it runs so calling it that like you do is
wrong. all you can do is fetch a page (we are ignoring file loads for
now).

ok, you can fetch a page by a browser or by any program that acts and
looks like a browser. these programs are called user agents and perl's
version is in a library called LWP.

and finally, a redirection does not RUN ANYTHING. it simply tells the
browser to IGNORE the rest of this page (which is why you never get
anything else from it) and load the page to which it redirects. so you
are not running or fetching ANYTHING in your existing script. you are
telling the BROWSER to fetch something else.

so now let's put this all together. redirect as you are doing will NEVER
work as its function is to cause the browser to go to somewhere
else. you lost control of the situation as soon as the browser is told
to redirect. so you need some way to fetch a page (NOT RUN A
SCRIPT. that is WRONG THINKING) from inside your cgi so YOU CAN KEEP
CONTROL of the situation. the key is CONTROL but you lose that with a
redirection.

so inside your cgi script you RUN AN LWP command like you have seen
several times in this thread. YOU GET the results in YOUR script and not
in the browser. BUT WATCH! YOU can send those results TO THE BROWSER
yourself with a print call. and THEN YOU KEEP CONTROL!!! wowie!!!
staying in control is the name of the game! now that you have control,
you just run the rest of your script and feel very happy.

and when 10 people tell you that you aren't running a script when you do
a redirection, try listening to them. you have showns a severe lacking
in the basics of how the web works. find a decent tutorial and learn
about it before you write code that interacts with it.

It is really frustrating when you need something done in the real
world and people tell you, find a decent tutorial and learn
about it before you write code that interacts with it. If I had
that much time I would not have asked here, I would have
worked it out myself. I started out at 11:00am asking what
would have only taken someone a few seconds to type the
code that I needed and and have yet at night to get the answer
in a useable form. I appreciate the help, but all I needed was
a clear example and a try this and see if this works. That
is what I would have given anyone who I could have helped.
Not, oh you have to look it you or you will never learn,
or if you know so little about it, pay someone to do it.
i hope this helps. if it doesn't, either you have no sense of humor or
else no senses whatsoever and should leave the programming to pros.

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

Thanks for the info
 
S

Sam Holden

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

So everyone else should bow to your wishes because you lacked
the perl ability or the planning ability to get something done
on time.

I'm sure numerous people here will do it for you for say $150/hour.

But, frankly I don't care (and I'm pretty sure no one else does) about
your deadlines.

People have told you the answer, you just don't have the domain
knowledge to realise, and when they try to tell you the domain knowledge
necessary to understand the answer you get all grumpy.

Not very effective. That'll work if you are paying $150/hour but you're not.
Well by this time I figured all I was going to get was more
go look it up you lead filled brained retard and figured I had
nothing left to lose.


I tried GET and HEAD and it did not work, do you have a
short example?

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

Jim Cochrane

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. As long as you find someone competent
wrt the problem you want solved, this greatly increases the chances that
your problem gets solved on time. In other words, it may help to post to a
newsgroup, but don't count on this as your only alternative. (Pardon me if
I'm pointing out the obvious.)
I tried GET and HEAD and it did not work, do you have a
short example?

Tip: In a situation like this, the more detail you give as to what happened
when it didn't work and what you expected to happen, the greater the chance
that someone will understand what is going wrong and be able to help you
get it working as you expect. (And if you're still looking for a
solution, I think it's not too late to do this - e.g., when you tried HEAD
and GET, what exactly happened and what did you expect to happen? What
does your code look like? Etc.)
 
J

John J. Trammell

One of two things, if I put in:

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

it go on its merry way and runs the script on domain.com and
the rest of the script is ignored, if I take it out it runs only
the script, I'm fickled and want it to do both. Run both
scripts, the one on domain.com first and wait until it is done.
Is that not forking() ? And everyone is now saying no it is not
forking.

No, I mean "What is really happening?". Until you address this
question, nobody can help you.
Not that I know of, I put in the URL to the script and it
does whatever voo doo it do.

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

David Grey

Jim said:
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.


As long as you find someone competent
wrt the problem you want solved, this greatly increases the chances that
your problem gets solved on time. In other words, it may help to post to a
newsgroup, but don't count on this as your only alternative. (Pardon me if
I'm pointing out the obvious.)

At least you were nice in being snippy.
 
C

Chris Mattern

David said:
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.

Then you need to pay somebody to fix it for you. You seem to have
mistaken this newsgroup for consultants on your payroll.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top