Try using backticks` ` until you read more about what Perl built-in's and modules can do for you. You can capture the response into a scalar or an array and then process it using the power of Perl's regular expressions. You can also use the system command if you don't want to process any return stuff from Win32 shell but just want to execute it.
use strict; use warnings; my @shell_rtn_val; print "Enter name of file to copy: "; my $file = <STDIN>; # open STDIN and get input chomp $file; # remove the \n $file =~s /\\/\\\\/g; # Convert to Win32 Shell path sep $file =~s /\//\\\\/g; # Use Unix path's too :-) @shell_rtn_val = `copy $file $file."bak"`; foreach(@shell_rtn_val){ #Let's look for interesting stuff and process it # $_ is implicitly searched for in each if # just like you wrote: $_ =~ m/regex-pattern/ if ( /(\d) file\(s\) copied/ ){ my $num = $1;print "You copied $num files"; } if ( /cannot find/ ){ print "System can't find a file by that name"; } if ( /syntax/ ){ print "Bad syntax"; `copy /?`; } }
There are modules which can make system interaction trivial...like File::Find for instance, or if you want to capture key strokes in Win32 you will need Term::ReadKey. The list is really endless, and the guys in here are smart as all get out.. they only ask that you do some homework and show some code before you ask a question! :) Cheers, James

In reply to Re: Shell commands on Win32 by JamesNC
in thread Shell commands on Win32 by andyram27

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.