Changeset 51


Ignore:
Timestamp:
Jan 8, 2006, 8:51:18 PM (20 years ago)
Author:
dmik
Message:

Fixed QProcess:

  • workingDirectory() was ignored;
  • environment variables added with putenv() to the parent process were not inherited by the child process started with NULL environment.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qprocess_pm.cpp

    r44 r51  
    4444#include "qtimer.h"
    4545#include "qregexp.h"
     46#include "qdir.h"
    4647#include "private/qinternal_p.h"
    4748#include "qt_os2.h"
     
    285286        envlist.resize( envlist.size() + 1 );
    286287        envlist[ pos ++ ] = 0;
     288    } else {
     289        // copy the entire environment (to let all variables added using
     290        // putenv() appear in the child process)
     291        uint sz = 1;
     292        for( const char * const *envp = environ; *envp != NULL; ++ envp )
     293            sz += strlen( *envp ) + 1;
     294        envlist.resize( sz );
     295        uint pos = 0;
     296        for( const char * const *envp = environ; *envp != NULL; ++ envp ) {
     297            sz = strlen( *envp ) + 1;
     298            memcpy( envlist.data() + pos, *envp, sz );
     299            pos += sz;
     300        }
     301        // add the terminating 0
     302        envlist[ pos ++ ] = 0;
    287303    }
    288304   
     
    605621    }
    606622
     623    // set the working directory
     624    QString curDir = QDir::currentDirPath();
     625    QDir::setCurrent( workingDir.path() );
     626#if defined(QT_QPROCESS_DEBUG)
     627    DosPrintf( tmpStderr != HF_ANY ? tmpStderr : realStderr,
     628               "QProcess::start(): curDir='%s', workingDir='%s'\n\r",
     629               curDir.local8Bit().data(),
     630               QDir::currentDirPath().local8Bit().data() );
     631#endif
     632   
    607633    // DosExecPgm()
    608634   
     
    611637    rc = DosExecPgm( pathBuf, sizeof(pathBuf), EXEC_ASYNCRESULT,
    612638                     buf.data(), envlist.data(), &resc, appNameFull.data() );
     639
     640    // restore the current directory
     641    QDir::setCurrent( curDir );
    613642   
    614643    // cancel STDIN/OUT/ERR redirections
Note: See TracChangeset for help on using the changeset viewer.