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 :

Qt Code:
  1. #!/bin/sh
  2.  
  3. pwd
  4. 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 :

Qt Code:
  1. void S3geoa2Launcher::runS3geoa2()
  2. {
  3.  
  4. QString program = "/usr2/home/jomarin/apps/testScript";
  5.  
  6. QString dirPath = "dir=";
  7.  
  8. dirPath.append("testUnix");
  9.  
  10. // create or modify the dir environment variable
  11. putenv((char *)dirPath.toStdString().c_str());
  12.  
  13. QProcess *s3geoa2Process = new QProcess(this);
  14.  
  15. // Setting the working directory of the application
  16. s3geoa2Process->setWorkingDirectory(QString(avantDistributeur->getPath().c_str()));
  17.  
  18. cout << "Launching " << program.toStdString() << endl;
  19. cout << "Working directory "<< avantDistributeur->getPath() << endl;
  20. cout << "Real working directory of the process "<< s3geoa2Process->workingDirectory().toStdString() << endl;
  21.  
  22. // Running the test script
  23. s3geoa2Process->startDetached(program);
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 

Finally, here is the output I get on the terminal :

Qt Code:
  1. Launching /usr2/home/jomarin/apps/testScript
  2. Working directory /usr2/home/jomarin/testUnix/cadre/avd
  3. Real working directory of the process /usr2/home/jomarin/testUnix/cadre/avd
  4. /usr2/home/jomarin/svn_repo/alstomTools/trunk/debug
  5. 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.