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\\cmd.exe","",0, NORMAL_PRIORITY_CLASS, ".", ) or die "Could not spawn process\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 for...here 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 $windowName...\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; }