I have a executable program myApp
(or myApp.exe
in Windows). I want to call this executable file in a C/C++ program, using system("myApp")
or QProcess:execute("myApp")
in Qt.
I want to get multiple return values from myApp
, so when calling this executable, I passed pointers as arguments, like this (in Qt)
float *pStates = new float[nState];
float *pControl = new float[nControl];
pControl[0] = 0.1;
pControl[1] = 0.2;
QString proStr;
proStr = "myApp ";
for (int i = 0; i < nState; i++)
{
proStr += (QString::number((uint64_t)pStates + i * sizeof(float)) + " ");
}
for (int i = 0; i < nControl; i++)
{
proStr += (QString::number(pControl[i]) + " ");
}
QProcess::execute(proStr);
The proStr
string might look like
myApp 140483171852384 140483171852388 140483171852392 140483171852396 140483171852400 0.1 0.2
Here 140483xxx numbers are pointer or physical address of pStates
.
And the code of myApp
looks like
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 8)
{
return 1;
}
float *x = atoi(argv[1]);
float *y = atoi(argv[2]);
float *z = atoi(argv[3]);
float *psi = atoi(argv[4]);
float *v = atoi(argv[5]);
float u = atof(argv[6]);
float a = atof(argv[7]);
*x = 1;
*y = 2;
*z = 3;
*psi = 1.23;
*v = 3.21;
return 0;
}
But this seems not working.
So, how can I get multiple return values from an external executable?