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