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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running perl scripts from within perl scripts

Status
Not open for further replies.

mincefish

Programmer
Sep 27, 2001
74
GB
I wanted to create a 'main menu' perl script that would pick up all the perl scripts in my scripts directory, and display them for me to choose. Then I would select a number, which would correspond to an element in an array. The array holds the name of all the .pl files in the directory. The idea would be to launch the chosen perl file.
I used:

Code:
$prog = $files[$input];
exec "perl C:/Perl/Scripts/$prog";

where
Code:
$file
is the array,
Code:
$input
is the number the user inputted, and
Code:
$prog
is the name of the file. As you can tell, I'm using perl on Windows.

However, when I do this, it appears to launch the script, but when I have to do any user input (which most of the scripts require), I get the following message:

Code:
The name specified is not recognized as an
internal or external command, operable program or batch file.

It seems as though the perl file isn't recognising my input, or maybe even the perl script isn't being run. Very confused.

Any help will be gratefully received!!
 
Looks like a path problem. I believe you are getting the error message because 'perl' is not in your path. One thing to try is using the full path to perl (e.g. C:/perl/bin/perl).
 
Thats weird, cos that's where I launch all my scripts from, but then at the top, I have
Code:
#!c:\perl\bin\perl
If I change the line to
Code:
exec "perl C:/Perl/bin/perl/$prog";
then I get a message saying it can't open perlscript [x], no such file or directory. Does this mean I need to save all my files in that directory? Or is there a way round it?

Thanks for your help, Raider2001
 
Assuming perl.exe is in the "C:/Perl/bin" directory, change the line to:

exec "C:/Perl/bin/perl C:/Perl/Scripts/$prog";

FYI, the line at the top '#!c:\perl\bin\perl' doesn't help Windows find perl.



 
Instead of using exec you can use do. It will execute the perl file within your menu program. Better, do will search the perl include path for the file, so you may not need to worry about the path part of the file names. Check out the documentation for the do command in the perlfunc manpage. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top