capture stderr from (process ...
Posted: Fri Dec 09, 2005 12:05 pm
Hi,
I'm trying porting from python to newlisp (of course) but python has possibility of assigning stderr output to a pipe when starting a process
eg from chatsniff1.0.py - http://chatsniff.sourceforge.net/
pipe = Popen('tethereal -i '+str(gDevices.index(gCurrentDevice) + 1)+' -l -V -R \"aim || ymsg || msnms || jabber\"', bufsize = 1, cwd = path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines = True)
while (process in newlisp syntax is : (process str-command int-pipe-in int-pipe-out [int-win32-option])
i.e. only stdin stdout directable to pipes.
The code in nl-filesys.c is:
CELL * p_process(CELL * params)
{
char * command;
int forkResult;
int inpipe = 0, outpipe = 0;
params = getString(params, &command);
if(params != nilCell)
{
params = getInteger(params, (UINT*)&inpipe);
getInteger(params, (UINT *)&outpipe);
}
if((forkResult = fork()) == -1)
return(nilCell);
if(forkResult == 0)
{
/* redirect stdin and stdout to pipe handles */
if(inpipe)
{
close(STDIN_FILENO);
if(dup2(inpipe, STDIN_FILENO) == -1) exit(0);
close(inpipe);
}
if(outpipe)
{
close(STDOUT_FILENO);
if(dup2(outpipe, STDOUT_FILENO) == -1) exit(0);
close(outpipe);
}
system(command);
exit(0);
}
could another option after [int-win32-option] be [int-pipe-err]
and newlisp do STDERR_FILENO to pipe?
Or is this not recommended?
Is there another way? - I see in
return value thread ( http://www.alh.net/newlisp/phpbb/viewtopic.php?t=789 ) that stderr can be handled from exec
Lutz:
> (exec "ls *.abc 2>&1")
("ls: *.abc: No such file or directory")
>
The 2>&1 spec tell ls to redirect error output to stdout.
but don't know enough about system() to know if that approach is possible for (process.
Any tips?
Nigel
I'm trying porting from python to newlisp (of course) but python has possibility of assigning stderr output to a pipe when starting a process
eg from chatsniff1.0.py - http://chatsniff.sourceforge.net/
pipe = Popen('tethereal -i '+str(gDevices.index(gCurrentDevice) + 1)+' -l -V -R \"aim || ymsg || msnms || jabber\"', bufsize = 1, cwd = path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines = True)
while (process in newlisp syntax is : (process str-command int-pipe-in int-pipe-out [int-win32-option])
i.e. only stdin stdout directable to pipes.
The code in nl-filesys.c is:
CELL * p_process(CELL * params)
{
char * command;
int forkResult;
int inpipe = 0, outpipe = 0;
params = getString(params, &command);
if(params != nilCell)
{
params = getInteger(params, (UINT*)&inpipe);
getInteger(params, (UINT *)&outpipe);
}
if((forkResult = fork()) == -1)
return(nilCell);
if(forkResult == 0)
{
/* redirect stdin and stdout to pipe handles */
if(inpipe)
{
close(STDIN_FILENO);
if(dup2(inpipe, STDIN_FILENO) == -1) exit(0);
close(inpipe);
}
if(outpipe)
{
close(STDOUT_FILENO);
if(dup2(outpipe, STDOUT_FILENO) == -1) exit(0);
close(outpipe);
}
system(command);
exit(0);
}
could another option after [int-win32-option] be [int-pipe-err]
and newlisp do STDERR_FILENO to pipe?
Or is this not recommended?
Is there another way? - I see in
return value thread ( http://www.alh.net/newlisp/phpbb/viewtopic.php?t=789 ) that stderr can be handled from exec
Lutz:
> (exec "ls *.abc 2>&1")
("ls: *.abc: No such file or directory")
>
The 2>&1 spec tell ls to redirect error output to stdout.
but don't know enough about system() to know if that approach is possible for (process.
Any tips?
Nigel