Basic question - having one program calling another

A

A. Sinan Unur

(e-mail address removed) (Chris Page) wrote in [email protected]:
I'm trying to get one program to call another, passing it values.
Reading the documentation lets me know in multiple places that it
can be done, but I haven't found the specific syntax needed.

How come?

perldoc -f system

is a good place to start to find out how to call an external program.

In a Perl program, you can access command line arguments via @ARGV. It is
documented in perldoc perlvar.
More precisely, (writing in pseudocode), I'd like to be able
to do the following:

PROGRAM 1
Call program 2, forwarding the constant '4'.
End

PROGRAM 2
Print the value passed to it.
End

Hmmmm ... I have lost count of how many times I asked the question "What
have you done so far?" just in the last two days.

The weather here is great, my office hours are over, I am feeling good,
etc etc, so I am just going to ask you to please read the posting
guidelines for the group, and take a look at the example below.

Remember, to research and try first, and then ask everyone else.

#! /usr/bin/perl

# t1.pl

use strict;
use warnings;

my $v = '4';

my $r = `perl t2.pl $v`;
chomp $r;

my $out = (($v eq $r) ? 'SUCCESS: ' : 'FAILURE ');
$out .= "Passed '$v' to t2, and received '$r'.\n";

print $out;

__END__

#! /usr/bin/perl

# t2.pl

use strict;
use warnings;

print "$ARGV[0]\n";

__END__

C:\asu1>perl t1.pl
SUCCESS: Passed '4' to t2, and received '4'.

Sinan
 
C

Chris Page

I'm trying to get one program to call another, passing it values.
Reading the documentation lets me know in multiple places that it
can be done, but I haven't found the specific syntax needed.

More precisely, (writing in pseudocode), I'd like to be able
to do the following:

PROGRAM 1
Call program 2, forwarding the constant '4'.
End

PROGRAM 2
Print the value passed to it.
End


The operating system is unix, though I suspect it doesn't matter.

Any help would be greatly appreciated.

Thanks,

-Chris Page
(e-mail address removed)
(fix email address if you wish to reply directly)
 
G

Gunnar Hjalmarsson

Chris said:
I'm trying to get one program to call another, passing it values.
Reading the documentation lets me know in multiple places that it
can be done, but I haven't found the specific syntax needed.

More precisely, (writing in pseudocode), I'd like to be able
to do the following:

PROGRAM 1
Call program 2, forwarding the constant '4'.
End

PROGRAM 2
Print the value passed to it.
End

Assuming you want a Perl program call another Perl program:

perldoc -f do
perldoc -f require

Now, it's often better to load modules instead of jumping between
different Perl programs.

perldoc perlmod

Check out those documents, and if you need further guidance, please post
actual Perl code with what you got so far, and let us know exactly what
the problem is.
 
A

A. Sinan Unur

(e-mail address removed) (Chris Page) wrote in
Thank you. @ARGV was what I was missing --

I am glad it worked out. However, I do not know your reasons for wanting
to do this. If it is a learning exercise, that's fine. Otherwise, please
take a look at Gunnar's response as well.
My apologies. I've now read the posting guidelines, should I get
lost enough to look for further help.

Thank you very much.

Sinan
 
C

Chris Page

"A. Sinan Unur" said:
perldoc -f system

is a good place to start to find out how to call an external program.

In a Perl program, you can access command line arguments via @ARGV. It is
documented in perldoc perlvar.

Thank you. @ARGV was what I was missing -- I was looking for its
equivalent in the wrong place (perldoc perlrun). I did spend a week
trying to figure out this question from perlboot, perltoot,
perlsub, perlrun, perlmod, and a number of the individual
functions (including "system"). But somehow I missed @ARGV,
probably being new to perl syntax/concepts.
Hmmmm ... I have lost count of how many times I asked the question "What
have you done so far?" just in the last two days.

The weather here is great, my office hours are over, I am feeling good,
etc etc, so I am just going to ask you to please read the posting
guidelines for the group, and take a look at the example below.

Remember, to research and try first, and then ask everyone else.

My apologies. I've now read the posting guidelines, should I get
lost enough to look for further help.

-Chris Page
(e-mail address removed)
 

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,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top