Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call perl from perl

Status
Not open for further replies.

przytulaguy

Technical User
Joined
Jul 24, 2006
Messages
8
Location
BE
what is the most recommended way to call a perl program from within a perl program.
I have prog1.pl and want to execute prog2.pl (in windows)
with parameters from within prog1
I can also be invoked from command line like :
prog2.pl --days=300 --subdir=d:\db2scripts\tmp --delete=Y
has prog2 to be declared in prog1 ?

Thanks for all info/help
Best Regards, Guy Przytula
 
Code:
#!/C:/Perl/bin/perl
#prog 1.pl
....
@results=`perl prog2.pl --days=300 --subdir=d:\db2scripts\tmp --delete=Y`;

Those are backticks, not single quotes, you could just call system either

Code:
#!/C:/Perl/bin/perl
#prog 1.pl
....
system("perl prog2.pl --days=300 --subdir=d:\db2scripts\tmp --delete=Y");
assuming that perl is in your PATH variable

HTH




Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
how you call it depends on what the called program does and if it returns any data back to the calling program.

If you need to caapture some returned data then backtiks or the qx// operator (does the same thing as backtiks).

If there is no return data use system() which will not return data but will return the exit status of the called program.

There is also exec() but that exits the calling program as soon as you use it.

There is also 'use' and 'require' which are ways to chain scripts and modules together.

You can look all of these up on:


look under "functions" and operators" in the references section on the left side of the page.
 
And there is also Win32::Process

Advantage is that you can continue on, or wait.
Also can set the Priority
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top