The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to automate mksysb via nim in AIX 5.3 barkath Shell Programming and Scripting 0 12-20-2007 03:46 PM
How to call a perl script from a shell script anumkoshy Shell Programming and Scripting 2 08-30-2007 01:23 AM
Wget call in a Perl script rahulrathod UNIX for Advanced & Expert Users 1 12-28-2005 03:45 AM
how to call a perl script from tcsh? megastar Shell Programming and Scripting 1 10-22-2005 02:48 PM
how can call perl script as command? umen UNIX for Dummies Questions & Answers 1 10-14-2005 06:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-18-2007
Registered User
 

Join Date: Oct 2007
Posts: 3
here document to automate perl script that call script

I am trying to use a here document to automate testing a perl script however when the perl script hits a
Code:
system(perl subscript.pl)
call, input is no longer entered into this subscript.

here is my script
Code:
$ cat test.sh
#ksh
for testcase
do
	program <<-EOF | tee -a funcscnlog.log 
	y
	functional
	2
	$testcase
	reload
	keep
	EOF
	cd log
	cp x.log x.$testcase.log
	cd ..
done
$ sh test.sh TC01 TC02 TC03
I don't really want to use expect as I don't want to install anything else on the test system.


while testing this i also found a odd out put from perl
Code:
$ cat test.pl
print "infirst ";
my $buffer = <STDIN>;
chomp($buffer);
print $buffer;
print "me";
system("perl runtest.pl");
print "\naftercall ";
my $buffer = <STDIN>;
print $buffer;
print "\n";

$ cat runtest.pl
print "\ninsubtest ";
my $buffer = <STDIN>;
chomp($buffer);
print $buffer;

$ perl test.pl
infirst a

insubtest b
bame
aftercall c
c

$
if you look closly you will see
Code:
system("perl runtest.pl");
is run before

Code:
print $buffer;
print "me";
Reply With Quote
Forum Sponsor
  #2  
Old 10-18-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Code:
	program <<-EOF | tee -a funcscnlog.log 
	y
	functional
	2
	$testcase
	reload
	keep
	EOF
(a) what is the "-" in front of EOF for?

(b) move all the text from "y" to "EOF" to the far left, at the very least the "EOF" must be in the far left column.
Reply With Quote
  #3  
Old 10-18-2007
Registered User
 

Join Date: Oct 2007
Posts: 3
the - in front of EOF tells the here doc to ignore any leading whitespace to allow it to be indented for easy looking code. There is no problem with the here document as I use this syntax on numrous other occassions successfully. The problem only occurs when the perl script "program" calls a subscript
Reply With Quote
  #4  
Old 10-22-2007
Registered User
 

Join Date: Oct 2007
Posts: 3
apparently it is due to the way perl buffer all 1024 bytes of stdin on the first call leaving it not readable for the rest subsequent calls.

I have replaced the
system("perl runtest.pl");

with
Code:
require "runtest.pl";
and all works
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0