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.
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
-Rick
Code:
#!c:/dwimperl/perl/bin/perl.exe
# PERL MODULES WE WILL BE USING
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.
$workbook1->SaveAs('c:\Users\tuckerri\Desktop\Report.xls');
}
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
-Rick