CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Catching STDIN



Jul 1, 2014, 2:52 PM

Post #1 of 5 (3281 views)
Catching STDIN Can't Post

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 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

(This post was edited by rekcut01 on Jul 2, 2014, 7:43 AM)

Veteran / Moderator

Jul 2, 2014, 11:00 AM

Post #2 of 5 (3265 views)
Re: [rekcut01] Catching STDIN [In reply to] Can't Post

Note quite sure to understand what you want to do, but my view is that STDIN is not something that exists in and of itself on a computer. It is, I think, best described as an entry point of a program or driver, often connected to the keyboard or some other device, but not necessarily. For example if you issue a Unix shell command such as:

sort my_file.txt | perl > output_file.txt

the pipe will connect the sort STDOUT to the Perl script STDIN


Jul 2, 2014, 11:16 AM

Post #3 of 5 (3262 views)
Re: [Laurent_R] Catching STDIN [In reply to] Can't Post

well, I have the above mentioned perl program, and it works just fine in a command window, it takes STDIN and gets the scanned number, parses the excel file and puts a time stamp in the column next to the number. What my problem is, it only works if the command window is in focus. I have it collapsed but people click on other things and takes the focus away, now my program isn't getting STDIN from the scanner anymore. So what I was attempting to do was put my program in a background mode, look for ANY STDIN (it could only come from the scanner at this point because there is no keyboard) and use it for my program. Clear as mud?? LOL, I think so, at this point I'm confusing myself also.

Veteran / Moderator

Jul 2, 2014, 12:25 PM

Post #4 of 5 (3255 views)
Re: [rekcut01] Catching STDIN [In reply to] Can't Post

Is this what you're looking for?

Win32::Daemon - Extension enabling Win32 Perl scripts to run as a true Win32 service


Jul 2, 2014, 2:11 PM

Post #5 of 5 (3198 views)
Re: [FishMonger] Catching STDIN [In reply to] Can't Post

I think so, let me look into it a little deeper.

Thanks FishMonger!



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives