开发环境:
ubuntu15 x64 + qte 4.8.6 + arm
Linux EmbedSky 3.0.35 #46 SMP PREEMPT Tue Mar 29 17:26:50 CST 2016 armv7l GNU/Linux(天嵌开发板)
1. 现象:
主程序A调用外部程序B,并且A退出, B解压 更新程序后再次加载A,则加载A失败。
原因不明,也写不了日志。
2.现象:
若直接运行B, B解压 更新程序后加载A,则加载A成功,
写不了日志(笔误
)。
3.现象:
在xp下测试反复循环加载正常,能写日志。
B程序主要代码:
QString g_currentPath;
int DoUnzip(QString sUpdatePackName, QString sUnzipPackPath)
{
qDebug() << sUpdatePackName << sUnzipPackPath;
int ret_value = doUncompress(sUpdatePackName.toLocal8Bit(), sUnzipPackPath.toLocal8Bit());
return ret_value;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile *fp = NULL;
do
{
//_asm{ int 3 };
g_currentPath = QDir::currentPath();
//QString sLogFile = QString("%1/update.log").arg(g_currentPath);
QString sLogFile = QString("%1/update.log").arg("/mnt/nfs/bin");
fp = new QFile(sLogFile);
if (fp == NULL){
qDebug() << "ImLog fopen error";
break;
}
if (!fp->open(QIODevice::ReadWrite|QIODevice::Append | QIODevice::Text)){
qDebug() << "ImLog fopen error";
break;
}
int nFileLen = fp->write("UpdateQt xxx ");
if (argc != 2){
qDebug() << "input param: xxx.zip!";
break;
}
nFileLen = fp->write(g_currentPath.toLocal8Bit());
nFileLen = fp->write("\n\r");
QString sSrc = QString::fromLocal8Bit(argv[1]);
QString sTmpPath = QString("%1/tmp").arg(g_currentPath);
QFile sourceDir(sSrc);
if(!sourceDir.exists()){ /**< 如果目标
目录不存在,则进行创建 */
qDebug() << sSrc << "not exists!";
nFileLen = fp->write(argv[1]);
nFileLen = fp->write("not exists!\n\r");
break;;
}
{
QDir dir(sTmpPath);
if (!dir.exists(sTmpPath)){
if (!dir.mkpath(sTmpPath)){
qDebug() << "mkpath false";
nFileLen = fp->write("mkpath false\n\r");
break;
}
}
if (DoUnzip(sSrc, sTmpPath)!=0){
qDebug() << "Unzip File False";
nFileLen = fp->write("Unzip File False\n\r");
break;
}
bool bOk = copyDirectoryFiles(sTmpPath, g_currentPath, true);
if (!bOk){
qDebug() << "copyDirectoryFiles false!";
nFileLen = fp->write("copyDirectoryFiles False\n\r");
break;
}
}
// delete tmp path;
if (!removeDirectory(sTmpPath)){
qDebug() << "delDirectoryFiles false!";
nFileLen = fp->write("delDirectoryFiles False\n\r");
//break;
}
QStringList arguments;
#ifdef _WIN32
QString program = QString("%1/E1800.exe").arg(g_currentPath);
arguments << "";
#else
QString program = QString("%1/E1800").arg(g_currentPath);
arguments << "-qws" <<"-font" << "unifont";
#endif
qDebug() << program;
nFileLen = fp->write(program.toLocal8Bit());
nFileLen = fp->write("\n\r");
QDir::setCurrent(g_currentPath);
QProcess *myProcess = new
QProcess(0);
myProcess->start(program, arguments);
//QTest::qSleep(1000*10);
} while (0);
if (fp){
fp->write("UpdateQt End\n\r");
fp->close();
}
return 0;
//return a.exec();
}
A调用程序代码:
int ImClient::DoUnzip()
{
#ifdef _WIN32
QString program = QString("%1/UpdateQt.exe").arg(g_env.filePathInfo.strAppPath);
#else
QString program = QString("%1/UpdateQt").arg(g_env.filePathInfo.strAppPath);
#endif
QStringList arguments;
arguments << m_sUpdatePackName;
QDir::setCurrent(g_env.filePathInfo.strAppPath);
LOGFILE("load updateQt.exe");
LOGSTR((g_env.filePathInfo.strAppPath.toLocal8Bit()));
QProcess *myProcess = new QProcess(0);
myProcess->start(program, arguments);
POST_MESSAGE( new ImEvent(QVariant(0), (QEvent::Type)WM_APP_QUIT));
return 0;
}