Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I had some luck with this:
use Win32::GuiTest qw(:ALL);
Win32::GuiTest CPAN link

Specifically, i was interacting with the LPR printing program from the command prompt. You didn't cite any specific code up there so I'm not sure exactly what you are trying, but I got LPR to interact with me on the command line with some form of the code below:

use strict; use warnings; use Win32; use Win32::Process; use Win32::GuiTest qw(:ALL); # start new command prompt my $process_object_cmd; Win32::Process::Create( $process_object_cmd, "C:\\Windows\\system32\\c +md.exe","",0, NORMAL_PRIORITY_CLASS, ".", ) or die "Could not spawn p +rocess\n"; &Set_Focus( "Command Prompt" ); my $ipAddress = 'test'; my $printName = 'test'; my $file = 'test'; # # Below in the qq[] is where I'd try sending some input to # whatever DOS app you're going I'm printing # to LPR... # SendKeys( qq[lpr -S $ipAddress -P $printName filename $file] ); SendKeys( "~" ); # # If you need to send more keystrokes or whatever, check # the documentation, pretty much any keyboard stuff is # possible with that module # # Subroutine: Set_Focus # Parameters: window Name # Description: Takes the name of a window, uses tools from GuiTest to +set focus # to that window so that we may send it input. Returns + window ID sub Set_Focus { my $windowName = shift; my $retryCounter = 0; my @windows = FindWindowLike( undef, "$windowName", "" ); unless ( @windows ) { @windows = FindWindowLike( undef, "$windowName", "" ); sleep(1); $retryCounter++; if( $retryCounter == 5 ) { die "Unable to gain control of $win +dowName...\nScript exiting...\n" } } my $focusError = (bring_window_to_front( $windows[0] )); return( $windows[0] ); } # Subroutine: bring_window_to_front # Parameters: window ID # Description: Takes in window ID, and sets it as foreground window sub bring_window_to_front { my $window = shift; my $success = 1; unless ( $window ) { $window = "notyet" } unless( $window eq "notyet" ) { SetActiveWindow($window); sleep(1); SetForegroundWindow($window); } if ( $window eq "notyet" ) { #print "* Could not set the window id: $window active\n"; $success = 0; } return $success; }
(My apologies if the example isn't exactly perfect, I chopped it out of a much larger program)

This example will probably just print the LPR help stuff, since I use 'test' for all the connection strings, just thought I'd let you know. Also added a couple extra comments in the code...

In reply to Re: Win32::Console question. by technojosh
in thread Win32::Console question. by ravenpi

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2018-06-22 19:45 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.