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

I want to execute commands in cmd by using perl program.I am using strawberry perl in windows.I am new to perl so any help will be highly appreciated.

Replies are listed 'Best First'.
Re: executing commands in cmd using perl
by atcroft (Abbot) on Dec 30, 2014 at 16:22 UTC

    My first stop would be system or exec-the former returns from the command, the latter turns control over to the process being executed and does not return to the script. If you are wanting the script to do control the process, or to process the output, then perhaps a read of the IPC (inter-process communications) doc would be informative. (You may also want to review the perlsec document, to be aware of possible areas of concern if you are dealing with potentially untrustworthy data.)

    Hope that helps.

    Update: 2014-12-30
    s/possibly (untrustworthy)/potentially $1/

      I have to first open cmd.exe and then execute command in cmd ,could you give me a small example please .
        If I'm understanding what you are asking (which seems unusual), your query is answered at stackoverflow. Example
        system 'start cmd.exe @cmd /k "Command"';
        Of course, that second bit isn't actually a Perl question.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Are you sure you need to open cmd.exe and then execute a command in it? Perl can issue a command to windows, even run a dos/windows .bat file without having to run cmd.exe. Perhaps you should tell a bit more specifically what you want to do rather than asking us how to do it the way you think it might be done. This looks like a case of XY Problem.
Re: executing commands in cmd using perl
by toolic (Bishop) on Dec 30, 2014 at 16:22 UTC