18.03.2013 - Bug fixes, add in/out speed diagnostic to PIProtocol, fixed PIConsole tab switch segfault, PIObject EVENT / EVENT_HANDLER mechanism update - new EVENT macros that use EVENT_HANDLER with raiseEvent implementation.
This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
This commit is contained in:
29
piprocess.cpp
Executable file → Normal file
29
piprocess.cpp
Executable file → Normal file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Process
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -55,7 +55,7 @@ void PIProcess::run() {
|
||||
//cout << "run" << endl;
|
||||
string str;
|
||||
/// arguments convertion
|
||||
int as = 0;
|
||||
as = 0;
|
||||
#ifdef WINDOWS
|
||||
//args.pop_front();
|
||||
piForeachC (PIString & i, args)
|
||||
@@ -96,30 +96,31 @@ void PIProcess::run() {
|
||||
f_in = PIFile::openTemporary(PIIODevice::ReadWrite);
|
||||
t_in = true;
|
||||
}
|
||||
f_in.open(PIIODevice::ReadWrite); f_in.close();
|
||||
//f_in.open(PIIODevice::ReadWrite); f_in.close();
|
||||
if (f_out.path().isEmpty()) {
|
||||
f_out = PIFile::openTemporary(PIIODevice::ReadWrite);
|
||||
t_out = true;
|
||||
}
|
||||
f_out.open(PIIODevice::WriteOnly); f_out.close();
|
||||
//f_out.open(PIIODevice::WriteOnly); f_out.close();
|
||||
if (f_err.path().isEmpty()) {
|
||||
f_err = PIFile::openTemporary(PIIODevice::ReadWrite);
|
||||
t_err = true;
|
||||
}
|
||||
f_err.open(PIIODevice::WriteOnly); f_err.close();
|
||||
//f_err.open(PIIODevice::WriteOnly); f_err.close();
|
||||
|
||||
str = args.front().stdString();
|
||||
is_exec = true;
|
||||
execStarted(PIString(str));
|
||||
#ifndef WINDOWS
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
#endif
|
||||
FILE * tf = 0;
|
||||
//cout << "exec" << endl;
|
||||
tf_in = tf_out = tf_err = 0;
|
||||
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||
//cout << f_out.path() << endl;
|
||||
if (g_in) tf = freopen(f_in.path().data(), "r", stdin);
|
||||
if (g_out) tf = freopen(f_out.path().data(), "w", stdout);
|
||||
if (g_err) tf = freopen(f_err.path().data(), "w", stderr);
|
||||
if (g_in) tf_in = freopen(f_in.path().data(), "r", stdin);
|
||||
if (g_out) tf_out = freopen(f_out.path().data(), "w", stdout);
|
||||
if (g_err) tf_err = freopen(f_err.path().data(), "w", stderr);
|
||||
#ifndef WINDOWS
|
||||
if (!wd.isEmpty()) as = chdir(wd.data());
|
||||
#endif
|
||||
@@ -142,16 +143,22 @@ void PIProcess::run() {
|
||||
} else
|
||||
piCout << "[PIProcess] \"CreateProcess\" error, " << errorString() << endl;
|
||||
#else
|
||||
|
||||
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||
if (execve(str.c_str(), a, e) < 0)
|
||||
piCout << "[PIProcess] \"execve\" error, " << errorString() << endl;
|
||||
} else {
|
||||
msleep(1);
|
||||
//cout << "wait" << endl;
|
||||
wait(&exit_code);
|
||||
/*if (tf_in != 0) fclose(tf_in);
|
||||
if (tf_out != 0) fclose(tf_out);
|
||||
if (tf_err != 0) fclose(tf_err);*/
|
||||
pid = 0;
|
||||
//cout << "wait done" << endl;
|
||||
}
|
||||
#endif
|
||||
execFinished(PIString(str), exit_code);
|
||||
is_exec = false;
|
||||
for (int i = 0; i < env.size_s(); ++i)
|
||||
delete e[i];
|
||||
@@ -162,7 +169,7 @@ void PIProcess::run() {
|
||||
for (int i = 0; i < args.size_s(); ++i)
|
||||
delete a[i];
|
||||
#endif
|
||||
//cout << "end" << endl;
|
||||
//cout << "end " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user