473,385 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

writing to a pipe on win32

Hi experts,
I need to write a perl script that will be called from a series of
executables chained thru pipes that read from STDIN and writes to
STDOUT. The following code works fine under regular circumstance. But
when there is a error down the pipe in one of the executables, the
pipe closes and then this script just exits. It does not print line
14. The troublesome line is line number 17. If I comment it out, the
script completes. From my very little perl knowledge, I was thinking
that in line 17, when we call "print $_" and the pipe broke due to the
error in another executable, it would generate SIGPIPE, but I get no
signal. Does SIGPIPE work on windows ?

1 sub signalhandler
2 {
3 print STDERR "*Received a SIG$_[0]\n";
4 }

5 my $Tmp_File = "c:/test_dir/testFile";

6 open(IN_FILE, ">$Tmp_File") || die "Open file error: $!";
7 binmode (IN_FILE);

8 while (<STDIN>) {
9 print IN_FILE ;
10 }
11 close(IN_FILE);

12 use sigtrap qw{handler signalhandler normal-signals
error-signals};

13 open(OUT_FILE, "$some_other_executable $Tmp_File |") || die
"Fork error: $!";
14 print STDERR "Opened file OUT_FILE!!\n";
15 binmode (OUT_FILE);
16 while (<OUT_FILE>) {
17 print $_;
18 }
19 unlink ($Tmp_File) || die "Remove file error: $!";

Thanks in advance.

Momena
Jul 19 '05 #1
1 5183
mo*****@yahoo.com (momena) wrote in message news:<1a**************************@posting.google. com>...
Hi experts,
I need to write a perl script that will be called from a series of
executables chained thru pipes that read from STDIN and writes to
STDOUT. The following code works fine under regular circumstance. But
when there is a error down the pipe in one of the executables, the
pipe closes and then this script just exits. It does not print line
14. The troublesome line is line number 17. If I comment it out, the
script completes. From my very little perl knowledge, I was thinking
that in line 17, when we call "print $_" and the pipe broke due to the
error in another executable, it would generate SIGPIPE, but I get no
signal. Does SIGPIPE work on windows ?

1 sub signalhandler
2 {
3 print STDERR "*Received a SIG$_[0]\n";
4 }

5 my $Tmp_File = "c:/test_dir/testFile";

6 open(IN_FILE, ">$Tmp_File") || die "Open file error: $!";
7 binmode (IN_FILE);

8 while (<STDIN>) {
9 print IN_FILE ;
10 }
11 close(IN_FILE);

12 use sigtrap qw{handler signalhandler normal-signals
error-signals};

13 open(OUT_FILE, "$some_other_executable $Tmp_File |") || die
"Fork error: $!";
14 print STDERR "Opened file OUT_FILE!!\n";
15 binmode (OUT_FILE);
16 while (<OUT_FILE>) {
17 print $_;
18 }
19 unlink ($Tmp_File) || die "Remove file error: $!";

Thanks in advance.

Momena


I ran it on unix (hpux) and I get SIGTERM, not SIGPIPE. Now that I
think about it again, it makes sense not to get a SIGPIPE, because I
am not directly writing to a pipe in line 17, even though other end os
STDOUT is a pipe. But in windows I get no signals. It seems very wrong
to me. Any comments ?
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Deepa | last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV file. It works fine. But I have some values in the dataset which have a comma within(eg. A,B,C). When I view the CSV file...
13
by: j. del | last post by:
I am just beginning to write programs... and my first task that I have set myself is to write a little program that will generate cryptic bywords from a source of text. A cryptic byword is...
6
by: Carson | last post by:
Hi, How to write c code such that it supports pipe in? i.e., echo "ABCD" | a.out (how to write a c-code which generates the binaries a.out that can take the pipe in input for further...
8
by: mojozoox | last post by:
Could you tell me scenarios in which core's dumped when writing to a pipe. write (pipefd,&Struct,structsize); on windows too this give a memory "read" violation. Could anyone tell me why. ...
3
by: EricR | last post by:
I am trying to use .NET to "tap into" a named pipe created by a non .NET 3rd party application. Specifically, the application is a table loading utility. It opens a named pipe and waits for input....
6
by: placid | last post by:
Hi all, I have been looking into non-blocking read (readline) operations on PIPES on windows XP and there seems to be no way of doing this. Ive read that you could use a Thread to read from the...
4
by: Gigs_ | last post by:
does anyone know some good tutorial on pipes in python? thx
2
by: MAx | last post by:
Hi guys, I am a c++ newbee and i am trying to write a file to a default printer. Please have a look at the code below and let me know if it'll work. I know that similar code in C will work. I...
1
by: sven _ | last post by:
Keywords: subprocess stdout stderr unbuffered pty tty pexpect flush setvbuf I'm trying to find a solution to <URL:http://bugs.python.org/issue1241>. In short: unless specifically told not to,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.