1)我的批处理脚本说 upgrade.bat 接受 2 个参数,如 ip 地址,升级 tar 球,然后使用 putty.exe 将文件传输到通过以太网电缆连接的 linux 机器。
bat 脚本中的示例
pscp -pw "blabla" "%TARGET_UPDATE_FILE%" user@"%TARGET_IP%":"%BASE_DIR%"/
其中 target_update_file = tar 球文件从 Qt 接受,目标 ip = ip 地址作为参数从 qt 接收到 bat 文件。
现在在 qt 上,在升级按钮代码中
void Qt_test::ReadOut()
{
QProcess *processInfo = dynamic_cast< QProcess* >( sender() );
if( processInfo )
{
ui->upgrade_info->append( processInfo->readAllStandardOutput() );
}
}
void Qt_test::ReadError()
{
QProcess *processInfo = dynamic_cast< QProcess* >( sender() );
if( processInfo )
{
ui->upgrade_info->append( processInfo->readAllStandardError() );
}
}
void Qt_test::on_file_browse_clicked()
{
ui->selected_file->setText( QFileDialog::getOpenFileName( this, tr( "Open File" ),
"/home",
tr( "Upgrade file ( *.tar.gz )" ) ) );
}
void Qt_test::on_file_upgrade_clicked()
{
QFileInfo upgradeFileInfo( ui->selected_file->text() );
if( !upgradeFileInfo.exists() )
{
QMessageBox::information( this, tr( "Information" ),
tr( "Unable to find file for upgrading!" ) );
return;
}
QString batchPath= QDir::currentPath() + "\\testUpgrade.bat" ;
QFileInfo batchFile( batchPath ) ;
if( !batchFile.exists() )
{
QMessageBox::information( this, tr( "Information" ),
tr("Failed to find the upgrade batch file....... ") ) ;
return;
}
//Check if cmd.exe is present in Clients system and is located at correct path
QFileInfo cmdFile( "C:\\Windows\\system32\\cmd.exe");
if( !cmdFile.exists() )
{
QMessageBox::information( this, tr( "Information" ),
tr("Failed to find the cmd.exe ... Check cmd.exe is installed and is in C:\\Windows\\system32\\ !") ) ;
return;
}
QFileInfo puttyFile( "C:\\Windows\\system32\\putty.exe");
if( !puttyFile.exists() )
{
QMessageBox::information( this, tr( "Information" ),
tr("Failed to find the putty.exe ... Check putty.exe(ideally version 0.62.0.0) is installed and is in C:\\Windows\\system32\\ !") ) ;
return;
}
QFileInfo plinkFile( "C:\\Windows\\system32\\plink.exe");
if( !plinkFile.exists() )
{
QMessageBox::information( this, tr( "Information" ),
tr("Failed to find the plink.exe ... Check plink.exe(ideally version 0.62.0.0) is installed and is in C:\\Windows\\system32\\ !") ) ;
return;
}
QString upgradeFile = upgradeFileInfo.absoluteFilePath();
QString ipAddress = ui->selected_ip->text();
qDebug() << " checksum valu is " <<checkSum.count() ;
QStringList arguments ;
arguments << " /c" << batchFile.absoluteFilePath()<< upgradeFile << ipAddress ;
// copying update
QProcess *processUpgrade = new QProcess( this );
if( processUpgrade )
{ std::cout <<" starting to upgrade " << std::endl ;
processUpgrade->setEnvironment( QProcess::systemEnvironment() ) ;
processUpgrade->setProcessChannelMode( QProcess::MergedChannels ) ;
processUpgrade->start( cmdFile.absoluteFilePath(), arguments ) ;
processUpgrade->waitForStarted() ;
connect( processUpgrade, SIGNAL( readyReadStandardOutput() ), this, SLOT( ReadOut() ) ) ;
connect( processUpgrade, SIGNAL( readyReadStandardError() ), this, SLOT( ReadErr() ) ) ;
}
}