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
capture stderr from (process ...
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
Hi Norman,
I'm not sure what you mean by switching?
I've experimented with redirecting 2>&1 with a single line command and it works:
> (process "ls *.abc 2>&1" procin procout)
11118
> (read-line myin)
"ls: *.abc: No such file or directory"
>
Looking more at system() it does start a shell for the process so I'll use the 2>&1 approach.
Longer term newlisp might like to look at having optional capture of stderr to its own pipe (Lutz?).
full eg from python
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)
global maintetherealpid
maintetherealpid = pipe.pid
pipe.stdin.close()
f = pipe.stdout
e = pipe.stderr
...
Nigel
I'm not sure what you mean by switching?
I've experimented with redirecting 2>&1 with a single line command and it works:
> (process "ls *.abc 2>&1" procin procout)
11118
> (read-line myin)
"ls: *.abc: No such file or directory"
>
Looking more at system() it does start a shell for the process so I'll use the 2>&1 approach.
Longer term newlisp might like to look at having optional capture of stderr to its own pipe (Lutz?).
full eg from python
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)
global maintetherealpid
maintetherealpid = pipe.pid
pipe.stdin.close()
f = pipe.stdout
e = pipe.stderr
...
Nigel
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia
-
- Posts: 429
- Joined: Tue Nov 11, 2003 2:11 am
- Location: Brisbane, Australia