Hello,
I'm trying to run an external program using the QProcess class. As I got some problems, for the moment, it is just a small sh script displaying one environment variable and the working directory :
#!/bin/sh
pwd
echo $dir
#!/bin/sh
pwd
echo $dir
To copy to clipboard, switch view to plain text mode
Here is the code I use to run this script from my Qt program :
void S3geoa2Launcher::runS3geoa2()
{
QString program
= "/usr2/home/jomarin/apps/testScript";
dirPath.append("testUnix");
// create or modify the dir environment variable
putenv((char *)dirPath.toStdString().c_str());
// Setting the working directory of the application
s3geoa2Process
->setWorkingDirectory
(QString(avantDistributeur
->getPath
().
c_str()));
cout << "Launching " << program.toStdString() << endl;
cout << "Working directory "<< avantDistributeur->getPath() << endl;
cout << "Real working directory of the process "<< s3geoa2Process->workingDirectory().toStdString() << endl;
// Running the test script
s3geoa2Process->startDetached(program);
}
void S3geoa2Launcher::runS3geoa2()
{
QString program = "/usr2/home/jomarin/apps/testScript";
QString dirPath = "dir=";
dirPath.append("testUnix");
// create or modify the dir environment variable
putenv((char *)dirPath.toStdString().c_str());
QProcess *s3geoa2Process = new QProcess(this);
// Setting the working directory of the application
s3geoa2Process->setWorkingDirectory(QString(avantDistributeur->getPath().c_str()));
cout << "Launching " << program.toStdString() << endl;
cout << "Working directory "<< avantDistributeur->getPath() << endl;
cout << "Real working directory of the process "<< s3geoa2Process->workingDirectory().toStdString() << endl;
// Running the test script
s3geoa2Process->startDetached(program);
}
To copy to clipboard, switch view to plain text mode
Finally, here is the output I get on the terminal :
Launching /usr2/home/jomarin/apps/testScript
Working directory /usr2/home/jomarin/testUnix/cadre/avd
Real working directory of the process /usr2/home/jomarin/testUnix/cadre/avd
/usr2/home/jomarin/svn_repo/alstomTools/trunk/debug
testUnix
Launching /usr2/home/jomarin/apps/testScript
Working directory /usr2/home/jomarin/testUnix/cadre/avd
Real working directory of the process /usr2/home/jomarin/testUnix/cadre/avd
/usr2/home/jomarin/svn_repo/alstomTools/trunk/debug
testUnix
To copy to clipboard, switch view to plain text mode
The dir environement variable is correctly set, but the working directory of the program is wrong .
Am I doing something wrong ?
Thanks in advance,
Joel Marin.
Bookmarks