in reply to Shell commands on Win32
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, Jamesuse 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 /?`; } }
|
|---|