Core: Fixed issue with reusing local process

git-svn-id: svn://ultimatepp.org/upp/trunk@10898 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-03-04 13:23:54 +00:00
parent 5f653a54e4
commit 3373a050ab
2 changed files with 34 additions and 30 deletions

View file

@ -4,8 +4,6 @@ using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
if(CommandLine().GetCount()) {
if(CommandLine()[0] == "localprocess") {
int ii = 0;
@ -28,36 +26,41 @@ CONSOLE_APP_MAIN
return;
}
StdLogSetup(LOG_COUT|LOG_FILE);
LocalProcess p;
ASSERT(p.Start2(GetExeFilePath() + " localprocess"));
ASSERT(p.IsRunning());
for(int pass = 0; pass < 2; pass++) {
LOG("========= PASS " << pass + 1);
ASSERT(p.Start2(GetExeFilePath() + " localprocess"));
ASSERT(p.IsRunning());
for(int i = 0; i < 10; i++)
p.Write(String(i + 'A', 1));
p.Write("Q");
String e, o, err, out;
while(p.Read2(o, e)) {
err << e;
out << o;
}
DUMP(err);
DUMP(out);
DUMP(p.IsRunning());
ASSERT(out == "65:A:0 66:B:2 67:C:4 68:D:6 69:E:8 70:F:10 71:G:12 72:H:14 73:I:16 74:J:18 ");
ASSERT(err == " ERRORA1 ERRORB3 ERRORC5 ERRORD7 ERRORE9 ERRORF11 ERRORG13 ERRORH15 ERRORI17 ERRORJ19");
ASSERT(!p.IsRunning());
for(int i = 0; i < 10; i++)
p.Write(String(i + 'A', 1));
p.Write("Q");
String e, o, err, out;
while(p.Read2(o, e)) {
err << e;
out << o;
o = Sys(GetExeFilePath() + " echo something different");
DUMP(o);
ASSERT(o == "echo something different");
o = Sys(GetExeFilePath(), Vector<String>() << "echo" << "one" << "two" << "\"three");
DUMP(o);
ASSERT(o == "echo one two \"three");
}
DUMP(err);
DUMP(out);
DUMP(p.IsRunning());
ASSERT(out == "65:A:0 66:B:2 67:C:4 68:D:6 69:E:8 70:F:10 71:G:12 72:H:14 73:I:16 74:J:18 ");
ASSERT(err == " ERRORA1 ERRORB3 ERRORC5 ERRORD7 ERRORE9 ERRORF11 ERRORG13 ERRORH15 ERRORI17 ERRORJ19");
ASSERT(!p.IsRunning());
o = Sys(GetExeFilePath() + " echo something different");
DUMP(o);
ASSERT(o == "echo something different");
o = Sys(GetExeFilePath(), Vector<String>() << "echo" << "one" << "two" << "\"three");
DUMP(o);
ASSERT(o == "echo one two \"three");
LOG("============= OK");
}

View file

@ -55,6 +55,7 @@ void LocalProcess::Free() {
if(epipe[1] >= 0) { close(epipe[1]); epipe[1] = -1; }
if(pid) waitpid(pid, 0, WNOHANG | WUNTRACED);
pid = 0;
exit_code = Null;
#endif
}