http://www.perlmonks.org?node_id=994251

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

Hi Monks,

i need to write a perl script which will execute dos commands in same machine as well as in other windows machine.

so below are my requirements.

how to execute dos commands in windows machine using perl?

e.g., rd /s/q <directory>

how to login to another windows machine and execute dos commands in that?

Any modules or any other way.

Please help.

Thank you...

Replies are listed 'Best First'.
Re: How to execute windows dos command using perl and how to login to another windows machine and execute dos command in that
by marto (Cardinal) on Sep 18, 2012 at 10:27 UTC

    File::Path is core and provides remove_tree. You can either mount remote drives in the usual manner or distribute your perl application.

      Hi Marto,

      at present we are using mks toolkit which is the unix environment for windows. so in our script we call "mks environment" and do lot of functions like rm,cp,chmod etc...

      now planning to remove mks toolkit and do the same functions using some other way

      so i think "File::Path" only provides some functionality which i needed.

      expecting something which satisfies mostly or everything.

      thank you...

Re: How to execute windows dos command using perl and how to login to another windows machine and execute dos command in that
by BrowserUk (Patriarch) on Sep 18, 2012 at 10:37 UTC
    how to login to another windows machine and execute dos commands in that?

    See PsExec for the easy way.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

    div

      Hi BrowserUk,

      already we are using some external tools.

      our need is to perform operation without using any external tools.

      so it would be better if you tell any other way in perl, or some perl modules, etc...

      thank you...

        I'm not sure what your definition is of "external tools". Psexec is part of the Sysinternals suite of tools that is now owned by Microsoft. These tools are simply an executable that you download (for free) and use on your Windows system. My personal view is to consider the Sysinternals tools as "native" tools that just are not shipped with the OS.

        For your desired task of using one Windows system to remotely run a command on another Windows system, I personally agree with BrowserUk that psexec will be the easiest method available.

        thanks for the help. now i can able to execute. but i face some issues. any idea.
        C:\>psexec \\vm-ntdivakar2 cleartool mount -all
        it returned error code.
        \ui is already mounted. \wpg is already mounted. cleartool exited on vm-ntdivakar2 with error code 1.
        So i got full pathname from the remote machine.
        C:\>psexec \\vm-ntdivakar2 which cleartool PsExec v1.98 - Execute processes remotely Copyright (C) 2001-2010 Mark Russinovich Sysinternals - www.sysinternals.com C:\Program Files (x86)\Rational\ClearCase\Bin/cleartool.exe which exited on vm-ntdivakar2 with error code 0.
        Then executed. but still it is returning error code.
        C:\>psexec \\vm-ntdivakar2 "C:\Program Files (x86)\Rational\ClearCase\ +Bin/cleartool.exe" mount -all \ui is already mounted. \wpg is already mounted. C:\Program Files (x86)\Rational\ClearCase\Bin/cleartool.exe exited on +vm-ntdivakar2 with error code 1.
Re: How to execute windows dos command using perl and how to login to another windows machine and execute dos command in that
by fluffyvoidwarrior (Monk) on Sep 18, 2012 at 12:55 UTC
    If you have a local windows network connection you can issue remote shell commands

    For example we use this to reboot a remote machine
    I don't see why you couldn't use perl to issue these commands directly or call a batch file

    shutdown /r /m \\wibble-win2003
    mstsc -v:wibble-win2003 /F –console

    Checkout the windows command reference, it's a very good resource for windows shell scripting. I don't know if it comes with non-server versions but it's downloadable from microsoft.

    Note:
    Log on to target computer over local network as administrator or it won't reboot cos you don't have permission.