Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Running Perl Scripts From Another Windows/DOS Directory (repost)

by svsingh (Priest)
on May 21, 2003 at 15:31 UTC ( [id://259746]=perlquestion: print w/replies, xml ) Need Help??

svsingh has asked for the wisdom of the Perl Monks concerning the following question:

Sorry for reposting this question. I had some errors in my original question which made it difficult for everyone to understand what I was asking. After reading Reposting Questions, I think it's okay to do this in this case. I hope I'm not causing too much clutter on the boards. Thanks.

I'm trying to run some scripts from the Windows command prompt. perl.exe is in my path, and the script is in another directory. Currently, the following command works:

c:\data> perl c:\scripts\test.pl

I'd like to add c:\scripts to some environment variable so running the following command would work:

c:\data> perl test.pl

I've tried setting LIB, LIB_PATH, LD_LIBRARY_PATH, and PERLLIB to c:\scripts with no luck. Is there a way to do this? I figure if I can do this in Java with CLASSPATH, then Perl may have an equivalent.

I would prefer not to change the association for .pl files. Currently running the file directly opens it in an editor and I want to keep that behaviour.

Thank you.

Replies are listed 'Best First'.
Re: Running Perl Scripts From Another Windows/DOS Directory (repost)
by benn (Vicar) on May 21, 2003 at 15:48 UTC
    perl -S will search PATH for a script, so simply add c:\scripts to your PATH.

    Info courtesy of perl -h :)

    Cheers,
    Ben.

      Thanks Ben! That was staring me in the face the entire time. I did scan through perl -h, but I guess I overlooked that one.
Re: Running Perl Scripts From Another Windows/DOS Directory (repost)
by svsingh (Priest) on May 21, 2003 at 15:35 UTC
    For what it's worth, the best solution I've come up with so far was to create a batch file containing:
    @echo off perl.exe -w c:\scripts\%1.pl

    It's saved in my %PATH% and allows me to run the following command:

    c:\data> runpl test

    It's hardly elegant, but it works. I'm banking on there being more than one way... :)

    Thanks again.

Re: Running Perl Scripts From Another Windows/DOS Directory (repost)
by cbro (Pilgrim) on May 21, 2003 at 15:59 UTC
    I'm not sure which version of Windows you are using, but, under Windows 9*, you need to add the following line at the very end of your autoexec.bat file:
    set PATH=%PATH%;C:\Perl\bin
    where C:\Perl\bin is the path to your perl bin directory. Save autoexec.bat and reboot your computer. This is basically what you were trying to accomplish from the start and will allow you to avoid using a separate batch script and/or the addition of flags such as '-S' to your perl script.
    Doing this on other Windows versions is similar, but for example with Win2K, the setting is made under 'Control Panel | System | Advanced | Environment Variables'.
    HTH,
    Chris

    UPDATE: Or I need to read the question more clearly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://259746]
Approved by zby
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found