1)我的批處理腳本說upgrade.bat接受2個參數,比如ip地址,升級tar球 然後用putty.exe將文件傳輸到通過以太網線連接的linux機器上。
例如蝙蝠腳本
PSCP -pw 「布拉布拉」 「%TARGET_UPDATE_FILE%」 用戶@ 「%TARGET_IP%」: 「%BASE_DIR%」/
其中target_update_file =焦油球文件接受從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())) ;
}
}
感謝您的建議。當我使用Google時,我發現QProcess,我想如果我使用'QProcess *過程; process-> start(「scp -pw rootpsswd c:\ tmp \ foo.tar.gz [email protected]:/ home/guest /」);'然後執行另一個命令,它會調用linux框中的bash腳本來解壓該文件並做需要的東西。你認爲這種方法好嗎? – samantha
@samantha這段代碼將簡單地啓動'scp'(安全拷貝),它是許多Linux發行版的SSH套件的一部分。如果您只想將文件從Windows傳輸到Linux,爲什麼不使用普通(S)FTP客戶端?你需要*在這裏寫下你自己的客戶嗎? – Gnosophilon
@ Gnosophilon,謝謝你的回覆。那麼,Linux的盒子已經有了ftp客戶端。在Windows上的Qt應用程序只是一個小應用程序瀏覽文件和trhough按鈕應升級文件在Linux機器/盒。升級我的意思是它應該將tarball轉移到linux機器上並運行bash腳本來解壓縮文件,檢查校驗和等等 – samantha