newbie01.perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi gurus,

Is there a module in Perl that allows running OS commands that are non-OS specific?

Basically, what am aiming to do is avoiding having to check for the OS and then run the OS-specific command via system or qw. For example, DOS uses del and *nix uses rm, DOS uses ren and *unix uses mv.

The *nix greps, I could probably get away with it with using regex but for the other "basic" commands, I can't ... hu hu hu. I believe I found a "find" module as well but am kinda hoping there is a module that "combine" all the other modules into one universal module.

For starters, am looking for a module that will allow me to run the same command regardless of which OS I run the Perl script on, that is, if such a module exists. Or are there Perl equivalent commands already some of the OS commands?

Your guidance will be very much appreciated.

  • Comment on Module for running OS-commands - non-OS dependent?

Replies are listed 'Best First'.
Re: Module for running OS-commands - non-OS dependent?
by toolic (Bishop) on Nov 29, 2009 at 01:17 UTC
Re: Module for running OS-commands - non-OS dependent?
by misterwhipple (Monk) on Nov 29, 2009 at 01:55 UTC

    Try recasting the problem. Don't think in terms of the various OS-specific commands -- del versus rm and ren versus mv. Rather, think in terms of what you wish to accomplish. "I want to change the name of an existing file."

    Then look for the Perl module(s) that can do that for you.

    --
    Any sufficiently interesting Perl project will depend upon at least one module that doesn't run on Windows.

Re: Module for running OS-commands - non-OS dependent?
by keszler (Priest) on Nov 29, 2009 at 01:16 UTC
    ppt - many of those "basic" commands have been rewritten in pure Perl.
Re: Module for running OS-commands - non-OS dependent?
by jacques (Priest) on Nov 29, 2009 at 01:12 UTC
    In many cases, there are Perl equivalents. They are not too difficult to find and can be a lot safer than evoking system commands from your program.
Re: Module for running OS-commands - non-OS dependent?
by biohisham (Priest) on Nov 29, 2009 at 14:01 UTC
    This really is a great post, sometimes it doesn't seem to be immediately sufficient to check for $^O and recollect what system commands to execute...UnxUtils gives you a front to execute *nix commands right on MSWin if you seek such functionality, it works for me just fine..

    Here's a quick shot at it:

    • create a folder (independent folder) for it, I named the folder 'UnixUtils'- note the tool is UnxUtils- and its path is 'C:\UnixUtils'.
    • Unzip the package to that folder.
    • Edit the perl 'Path' in the 'environmental variables' to include a path to 'C:\UnixUtils\usr\local\wbin'
    You're good to go...
    #This is from a Windoze box cmd : C:\Documents and Settings\m>perl - print `ls -la`; __END__ total 10817 drwxrwxrwx 1 user group 0 Jun 6 2009 . drwxrwxrwx 1 user group 0 May 28 2009 .. drwxrwxrwx 1 user group 0 Jun 13 2009 01-First Week drwxrwxrwx 1 user group 0 Jun 18 2009 02-Second Week drwxrwxrwx 1 user group 0 Jun 29 2009 03-Third Week drwxrwxrwx 1 user group 0 Jul 4 07:31 04-fourth week

    check the page http://unxutils.sourceforge.net/ it got some of the commands supported by the UnxUtils tool though the page is not so up-to-date but it can give a nice overview.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: Module for running OS-commands - non-OS dependent?
by Anonymous Monk on Nov 30, 2009 at 04:38 UTC
    Maybe not a direct answer to your question ( because I don't have one ), but you can install Cygwin in Windows and create that *nix environment with all the necessary Unix commands and power tools, plus perl 5.10.0.