[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #48149] popen2 on Windows requires delay
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #48149] popen2 on Windows requires delay |
Date: |
Mon, 6 Jun 2016 16:02:25 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 |
URL:
<http://savannah.gnu.org/bugs/?48149>
Summary: popen2 on Windows requires delay
Project: GNU Octave
Submitted by: rik5
Submitted on: Mon 06 Jun 2016 09:02:22 AM PDT
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: dev
Operating System: Microsoft Windows
_______________________________________________________
Details:
There is example code in the docstring for popen2. The code is
[in, out, pid] = popen2 ("sort", "-r");
fputs (in, "these\nare\nsome\nstrings\n");
fclose (in);
EAGAIN = errno ("EAGAIN");
done = false;
do
s = fgets (out);
if (ischar (s))
fputs (stdout, s);
elseif (errno () == EAGAIN)
pause (0.1);
fclear (out);
else
done = true;
endif
until (done)
fclose (out);
waitpid (pid);
This works correctly on Linux, but fails on Windows. The problem is that the
initial call to fgets (out) returns -1 (EOF) immediately. I can get the code
to work by adding a small delay before starting the do loop.
This works
[in, out, pid] = popen2 ("sort", "-r");
fputs (in, "these\nare\nsome\nstrings\n");
fclose (in);
EAGAIN = errno ("EAGAIN");
done = false;
pause (0.05); # 50 millisecond pause
do
s = fgets (out);
if (ischar (s))
fputs (stdout, s);
elseif (errno () == EAGAIN)
pause (0.1);
fclear (out);
else
done = true;
endif
until (done)
fclose (out);
waitpid (pid);
I tried using fflush (in) before fclose, but that didn't help. The problem is
either in the popen2 call, which is Windows specific and located in
liboctave/system/lo-sysdep.cc. Or Windows itself has problems with
concurrency.
I've attached the test code to this bug report.
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Mon 06 Jun 2016 09:02:22 AM PDT Name: tst_popen2.m Size: 339B By:
rik5
<http://savannah.gnu.org/bugs/download.php?file_id=37409>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?48149>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #48149] popen2 on Windows requires delay,
Rik <=