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

Hello, i need some command which copyes everything what is seen on CMD screen? For example, i make a perl programm, which makes at the beginning system ('clear'); and than system ('systeminfo'); and than i need that perl "copyes" this information and sets it like "=$a" for example, so that i can worl with this and save it for example in a *.TXT document ... Is perl able to do this ? Thank you for your time
  • Comment on Can Perl copy informations from screen in CMD?

Replies are listed 'Best First'.
Re: Can Perl copy informations from screen in CMD?
by GrandFather (Saint) on Mar 18, 2007 at 21:35 UTC

    Do you need to "read the screen", or is it that you want to capture output from certain command line applications, or is there specific information you are trying to determine and the only way you have thought to do it is using system tools you know about?

    You may do better to describe the higher level problem that you are trying to solve. "Reading the screen" is seldom the best way to do things.


    DWIM is Perl's answer to Gödel
      yep that what i was looking for ... i had no idea that its so simple thank you - i am pretty new to perl .)
Re: Can Perl copy informations from screen in CMD?
by Corion (Patriarch) on Mar 18, 2007 at 21:33 UTC

    Maybe the backticks (`...`) or the qx() operator does what you want?

    use strict; my $info = `systeminfo`; print "I got the following information:\n"; print "***$info***\n";
      Or even:
      use strict; open (my $info, '>', 'info.txt') or die "info.txt: $!"; print $info qx(systeminfo); close($info)
      You can read the screen with Win32::Console->ReadChar but you really don't want to.