Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Help catching STDIN in background

Help catching STDIN in background

Help catching STDIN in background

Is there a way to catch <STDIN> from a background process running in windows? I want to write a service that loops, running it in the back ground and just listen for <STDIN>, when it gets input go automatically and run a perl program.


use strict; 
use warnings; 
use integer; 
use CGI; 
use Win32::OLE; 
use Win32::OLE qw(in with); 
use Win32::OLE::Variant; 
use Win32::OLE::Const 'Microsoft Excel'; 
use Spreadsheet::ParseExcel::Worksheet; 
use Spreadsheet::ParseExcel::SaveParser; 
use Spreadsheet::WriteExcel; 
use Time::Piece; 
use Data::Dumper; 
use 5.010001; 
print "Content-type: text/html\n\n"; 
while (1) 
	#my $input = <STDIN>; 
	my $input; 
	if (-t STDIN) 
		print "hello"; 
		$input = <STDIN>; 
		$input =~ s/\r\n//; 
	#$input =~ s/\r\n//; 
	my $global_col; 
	my $global_row; 
	my $parser   = Spreadsheet::ParseExcel::SaveParser->new(); 
	my $workbook = $parser->parse('C:\Users\tuckerri\Desktop\Report.xls'); 
	if ( !defined $workbook )  
		die $parser->error(), ".\n";  
	my $worksheet = $workbook->worksheet(0); 
	for my $worksheet ( $workbook->worksheets() )  
		my ( $row_min, $row_max ) = $worksheet->row_range(); 
		my ( $col_min, $col_max ) = $worksheet->col_range(); 
		for my $row ( $row_min .. $row_max )  
			for my $col ( $col_min .. $col_max )  
				my $cell = $worksheet->get_cell( $row, $col ); 
				next unless $cell; 
				my $cmp_string = $cell->value(); 
				#print "$row $col \n"; 
				if ($cmp_string eq $input) 
					my $out_time = localtime; 
					my $n= &mod_spreadsheet($row, $col); 
sub mod_spreadsheet() 
	my $sub_row = $_[0]; 
	my $sub_col = $_[1]; 
	my $date = localtime->strftime('%m/%d/%y %H:%M', localtime); 
	print "$date \n"; 
	#my $sub_out_time = $_[2]; 
	#my $out_time = sub main::localtime; 
	#print $sub_out_time; 
	my $parser1   = Spreadsheet::ParseExcel::SaveParser->new(); 
	my $workbook1 = $parser1->Parse('c:\Users\tuckerri\Desktop\Report.xls'); 
	if ( !defined $workbook1 )  
		die $parser1->error(), ".\n"; 
	my $worksheet1 = $workbook1->worksheet(0); 
	my $cell1 = $worksheet1->get_cell( $sub_row, $sub_col + 1 ); 
	$worksheet1->AddCell( $sub_row, $sub_col + 1, $date ); 
	## Write over the existing file or write a new file. 

I would like to put this in the background listening for <STDIN>.... the PC I have this on has no keyboard, mouse or monitor so the only input will be from the scanner.

Is there a way to make this happen?

Thanks in advance

RE: Help catching STDIN in background

This isn't an elegant solution, but I've used this idea / concept in a couple of programs.
Read the documentation on GuiTest and some of this will make more sense.

- Start your program and give it an easily identifiable title
- use Win32:GuiTest ;
- $hWnd = FindWindowLike('your program title') ; # See documentation on GuiTest
You'll get a window handle out of this (possibly @hWnd if the name is generic)
- ($l,$t,$r,$b) = GetWindowRect(hWnd) ; # Get the coordinates of your window
- Each time you want to look for STDIN use
($x,$y) = GetCursorPos() ;
- check to see if ($x, $y) are in the borders of your program window
- If so, break out for generic: print "What now? " ; $response = <STDIN> ;
type input retrieval. If ($x, $y) are not in your borders - just keep
doing what you were doing before.
*** Caution:
- Generate a function that will test the state of the window $hWnd.
If the user moves it, ($l,$t,$r,$b) values will change

RE: Help catching STDIN in background

Hi Rick,

I've not written this kind of Perl script for Windows but you do something similar to this in *nix when you write a daemon process - you close and then reopen stdin, stdout and stderr. I'll have a look around.


RE: Help catching STDIN in background

My answer (above) is complete twaddle...

I don't think you can *quite* do what you're asking, but there's probably a way around it.

Can you start the process on the end of a pipe and then block until there's something to read?

CODE --> Perl

open(P, 'scanner_proc |')
#  do whatever you're going to do with the scanner output


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close