PDA

View Full Version : executing script from c++ code



oogolov
11th January 2013, 10:36
I develop an application using Qt/c++/ubuntu (further parent app).
I need to execute another open source application from my c++ code (further child app).
To run child application is to execute a bash script. The script sets several global variables and then calls python application.
The script works well from command line.

I tried to use Qt QProcess class but I have got only cascade of error messages from child python application.
Can I use embedding python into my c++ code by means of functions from Python.h?
What need I to do with global variables in the case?

Please give me an advice to call the script from c++ code. What is my alternatives? What is the best of them?

Santosh Reddy
11th January 2013, 11:32
What did you run as QProcess?
You may want to run bash shell as QProcess and script as an argurmant.

oogolov
14th January 2013, 10:34
Dear Santosh, thank you.

Here is fragment of my code:


//-------------------
void MainWindow::CodeAsterError()
{
ui->textBrowserError->append(caProcess->readAllStandardError());
}

void MainWindow::CodeAsterOut()
{
QByteArray byteArray = caProcess->readAllStandardOutput();
QStringList strLines = QString(byteArray).split("\n");

foreach (QString line, strLines)
{
ui->textBrowserOut->append(line);
}
}

void MainWindow::on_pushButton_clicked()
{
QString program = "/home/oogolov/aster/bin/as_run";
QStringList arguments;
arguments << "/home/oogolov/GeoFEA/GeoFEA2D/WorkDir/Calc.export";

connect (caProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(CodeAsterOut()));
connect (caProcess, SIGNAL(readyReadStandardError()), this, SLOT(CodeAsterError()));

caProcess->start(program,arguments);
//caProcess->start("/bin/bash", QStringList() << "/home/oogolov/aster/bin/as_run" << "/home/oogolov/GeoFEA/GeoFEA2D/WorkDir/Calc.export");
// commented operator works too
caProcess->waitForReadyRead(100);
}
//----------------------

When I run (Build/Run) my application it works. But when I debug (Debug/Start Debugging) I get following error:

*************************
Traceback (most recent call last):
File "<string>", line 1, in <module>

File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/main.py", line 109, in main
start()
File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/main.py", line 51, in start
run = AsterRun()
File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/run.py", line 186, in __init__
self.LoadExtensions()
File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/run.py", line 297, in LoadExtensions
import asrun.maintenance
File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/maintenance.py", line 42, in <module>

from asrun.build import AsterBuild
File "/home/oogolov/aster/lib/python2.7/site-packages/asrun/build.py", line 31, in <module>
from zipfile import ZipFile
File "/opt/QtSDK/debugger/Desktop/lib/python2.7/zipfile.py", line 6, in <module>
import io
File "/opt/QtSDK/debugger/Desktop/lib/python2.7/io.py", line 60, in <module>
import _io
ImportError: /opt/QtSDK/debugger/Desktop/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_FromObject
****************************

Could you help me to repair this "Import, PyUnicode" state?