i'm assuming here that you actually want the output from the find command, and not the exit code. as your code is written, it will return the exit code.

below is some code that shows you the different ways of accomplishing your task.

#!perl -w use strict; my $file = 'c:\autoexec.bat'; my $pattern = 'PATH'; my $seperator = '----------'; print "\n---find 1: using system\n"; my $t=system("find /c \"$pattern\" $file") ; print "->", $t, "<-\n"; print "\$t is the exit code\n"; print "\n---find 2: using `backticks`\n"; my $u=`find /c "$pattern" $file`; print "->", $u, "<-\n"; print "\$u is the output\n"; print "\n---find 3: 100% pure perl\n"; open(FILE, "< $file") or die("ERROR: failed to open file, $!"); # $count is initialized to prevent print from complaining # if no matches are found my $count=0; while( <FILE> ) { ++$count if /$pattern/; } close(FILE) or die("ERROR: failed to close file, $!"); print "->", $count, "<-\n"; print "\$count is the match count\n"; print " -or, if you really want the same output format as find-\n"; print "$seperator $file: $count\n";
the output is:

C:\WINDOWS\Desktop>perl test.pl ---find 1: using system ---------- c:\autoexec.bat: 6 ->0<- $t is the exit code ---find 2: using `backticks` -> ---------- c:\autoexec.bat: 6 <- $u is the output ---find 3: 100% pure perl ->6<- $count is the match count -or, if you really want the same output format as find- ---------- c:\autoexec.bat: 6
on my windows98 box.

~Particle


In reply to Re: How do I call a DOS command with a /C variable in PERL ? by particle
in thread How do I call a DOS command with a /C variable in PERL ? by sheabo

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.