Skip to content
Snippets Groups Projects
Commit c93e07fc authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

support stderr better (EXPERIMENTAL)

Rev: NT/tools/lib.pike:1.21
Rev: NT/tools/sprshd:1.22
parent 6ea338f2
Branches
Tags
No related merge requests found
......@@ -169,7 +169,7 @@ int silent_do_cmd(string *cmd, mixed|void filter, int|void silent)
case "SPRSH":
if(string tmp=getenv("REMOTE_VARIABLES"))
{
array vars=({});
array vars=({"__handles_stderr=1"});
foreach(tmp/"\n",string var)
if(search(var,"=")!=-1)
vars+=({var});
......@@ -215,6 +215,11 @@ int silent_do_cmd(string *cmd, mixed|void filter, int|void silent)
{
return Stdio.stdout->write(s);
}
int werr(string s)
{
return Stdio.stderr->write(s);
}
};
object inout;
......@@ -265,6 +270,8 @@ int silent_do_cmd(string *cmd, mixed|void filter, int|void silent)
return strlen(s);
}
int werr(string s) { return write(s); }
void create()
{
rl->enable_history(512);
......@@ -336,11 +343,19 @@ int silent_do_cmd(string *cmd, mixed|void filter, int|void silent)
werror("Connection closed!\n");
exit(1);
}
sscanf(s,"%4c",int len);
sscanf(s,"%c%3c",int channel, int len);
if(!len) break;
s=f->read(len);
s=replace(s,"\r\n","\n");
if(!silent) inout->write(s);
if(!silent)
{
switch(channel)
{
case 0: /* Backwards compatibility */
case 1: inout->write(s); break; // stdout
case 2: inout->werr(s); break; // stderr
}
}
if(filter) ret+=s;
}
if(filter) filter(ret);
......
......@@ -79,6 +79,17 @@ string opt_path(string p1, string p2)
return ( ( ((p1||"") + ";" + (p2||"")) / ";" ) - ({""}) ) * ";";
}
void myproxy(object pi, object io, int channel)
{
while(1)
{
string s=pi->read(1000,1);
if(!s || !strlen(s)) break;
io->write(sprintf("%c%3c%s",channel,strlen(s),channel,s));
}
}
void handle_incoming_connection(object(Stdio.File) io)
{
object p;
......@@ -92,10 +103,12 @@ void handle_incoming_connection(object(Stdio.File) io)
}
object pi=Stdio.File();
object pe=Stdio.File();
#ifdef NO_IPC
object p2=pi->pipe();
object p23=pi->pipe();
#else
object p2=pi->pipe(Stdio.PROP_IPC);
object pe2=pe->pipe(Stdio.PROP_IPC);
#endif
string dir=cmd[0];
cmd=cmd[1..];
......@@ -254,23 +267,27 @@ void handle_incoming_connection(object(Stdio.File) io)
#ifndef WINE
"stdin":io,
"stdout":p2,
"stderr":p2,
"stderr":pe2,
#endif
"cwd":dir,
"env":env,
]));
};
destruct(p2);
destruct(pe2);
if(!err)
{
#ifdef NO_IPC
thread_create(monitor,p2,p);
#endif
while(1)
if(env->__handles_stderr)
{
string s=pi->read(1000,1);
if(!s || !strlen(s)) break;
io->write(sprintf("%4c%s",strlen(s),s));
thread_create(myproxy,pe,io,2);
myproxy(pi,io,1);
}else{
thread_create(myproxy,pe,io,0);
myproxy(pi,io,0);
}
io->write(sprintf("%4c",0));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment