help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in popen2???


From: Pedro Luis Lucas Rosado
Subject: Bug in popen2???
Date: Thu, 29 Mar 2007 16:08:16 +0100

Hi, I have found a bug in popen2 function, I think.

Line:

fcntl (nth (stdout_pipe, 1), F_SETFL, O_NONBLOCK) 

doesn't work. I have commented it and all works ok.

The new popen2 function will be:

function [in, out, pid] = popen2 (command, args)
in = -1;
out = -1;
pid = -1;
if (nargin == 1 || nargin == 2)
if (nargin == 1)
args = "";
endif
if (ischar (command))
[stdin_pipe, stdin_status] = pipe ();
[stdout_pipe, stdout_status] = pipe ();
if (stdin_status == 0 && stdout_status == 0)
pid = fork ();
if (pid == 0)
## In the child.
fclose (nth (stdin_pipe, 2));
fclose (nth (stdout_pipe, 1));
dup2 (nth (stdin_pipe, 1), stdin);
fclose (nth (stdin_pipe, 1));
dup2 (nth (stdout_pipe, 2), stdout);
fclose (nth (stdout_pipe, 2));
if (exec (command, args) < 0)
error ("popen2: unable to start process `%s'", command);
exit (0);
endif
elseif (pid)
## In the parent.
fclose (nth (stdin_pipe, 1));
fclose (nth (stdout_pipe, 2));

%This lines doesn't work

%if (fcntl (nth (stdout_pipe, 1), F_SETFL, O_NONBLOCK) < 0)
% error ("popen2: error setting file mode");
%else
in = nth (stdin_pipe, 2);
out = nth (stdout_pipe, 1);
%endif
elseif (pid < 0)
error ("popen2: fork failed -- unable to create child process");
endif
else
error ("popen2: pipe creation failed");
endif
else
error ("popen2: file name must be a string");
endif
else
usage ("[in, out, pid] = popen2 (command, args)");
endif

---------------------------------------------------------
Registra tu dominio en http://dominios.ya.com/. Con cada registro te regalamos 
20 cuentas de correo de 100MB cada una.
Ya.com ADSL 24h + Llamadas Nacionales y Locales 24h + Llamadas a MÓVILES.
Desde 9,95 €/mes+IVA. http://acceso.ya.com/ADSLllamadas/3mbvoz/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]