PIString replace pibytearray by char *

This commit is contained in:
Andrey
2022-04-25 11:42:58 +03:00
parent cf48c9ebf7
commit 765ef7368e
5 changed files with 106 additions and 131 deletions

View File

@@ -115,44 +115,37 @@ void PIProcess::startProc(bool detached) {
//cout << "run" << endl;
PIString str;
/// arguments convertion
#ifdef WINDOWS
int as = 0;
piForeachC (PIString & i, args)
as += i.lengthAscii() + 3;
const char * argscc[args.size()+1];
int argsl[args.size()];
for (int i = 0; i < args.size_s(); ++i) {
argscc[i] = args[i].data();
argsl[i] = strlen(argscc[i]);
as += argsl[i] + 3;
}
argscc[args.size()] = 0;
#ifdef WINDOWS
char * a = new char[as];
memset(a, ' ', as - 1);
as = 0;
for (int i = 0; i < args.size_s(); ++i) {
str = args[i];
a[as] = '"';
memcpy(&(a[as + 1]), str.data(), str.lengthAscii());
a[as + str.lengthAscii() + 1] = '"';
as += str.lengthAscii() + 3;
memcpy(&(a[as + 1]), argscc[i], argsl[i]);
a[as + argsl[i] + 1] = '"';
as += argsl[i] + 3;
}
a[as - 1] = 0;
//piCout << a;
#else
//piCout << "#" << args;
char * a[args.size_s() + 1];
for (int i = 0; i < args.size_s(); ++i) {
str = args[i];
//piCout << i << str << str.size() << str.lengthAscii() << str.lengthAscii() << str.lengthAscii();
a[i] = new char[str.lengthAscii() + 1];
memcpy(a[i], str.data(), str.lengthAscii());
a[i][str.lengthAscii()] = 0;
}
a[args.size_s()] = 0;
#endif
#ifndef WINDOWS
/// environment convertion
char ** e = new char*[env.size_s() + 1];
const char * envcc[env.size()+1];
envcc[env.size_s()] = 0;
for (int i = 0; i < env.size_s(); ++i) {
str = env[i];
e[i] = new char[str.lengthAscii() + 1];
memcpy(e[i], str.data(), str.lengthAscii());
e[i][str.lengthAscii()] = 0;
//cout << e[i] << endl;
envcc[i] = env[i].data();
}
e[env.size_s()] = 0;
#endif
/// files for stdin/out/err
t_in = t_out = t_err = false;
if (f_in.path().isEmpty()) {
@@ -196,7 +189,7 @@ void PIProcess::startProc(bool detached) {
0, // Thread handle not inheritable
false, // Set handle inheritance to FALSE
detached ? DETACHED_PROCESS/*CREATE_NEW_CONSOLE*/ : 0, // Creation flags
0,//e, // Use environment
0,//envcc, // Use environment
wd.isEmpty() ? 0 : wd.data(), // Use working directory
&(PRIVATE->si), // Pointer to STARTUPINFO structure
&(PRIVATE->pi))) // Pointer to PROCESS_INFORMATION structure
@@ -209,7 +202,7 @@ void PIProcess::startProc(bool detached) {
#else
//cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
if (execve(str.data(), a, e) < 0)
if (execve(str.data(), argscc, envcc) < 0)
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
} else {
piMinSleep;
@@ -224,14 +217,8 @@ void PIProcess::startProc(bool detached) {
#endif
if (!detached) execFinished(str, exit_code);
is_exec = false;
for (int i = 0; i < env.size_s(); ++i)
delete e[i];
delete[] e;
#ifdef WINDOWS
delete a;
#else
for (int i = 0; i < args.size_s(); ++i)
delete a[i];
delete[] a;
#endif
}