【发布时间】:2012-06-07 15:53:16
【问题描述】:
我需要有关从 Windows 中的 Qt 应用程序调用的批处理脚本(.bat)执行 bash 脚本的帮助。
问题概述: 我需要通过 Qt 应用程序将文件从 Windows 传输到 Linux 机器,并在 linux 中运行 bash 脚本来执行一些命令。
到目前为止我所做的: 我可以通过 Qt 应用程序成功地将文件从 Windows 传输到 Linux 机器。 Qt 应用程序调用传输文件的批处理文件
例子
void Qt_intro101::on_file_upgrade_clicked()
{
QFileInfo fileInfo( ui->selected_file->text() );
if( !fileInfo.exists() )
{
QMessageBox::information(this, tr("Information"),
tr("Unable to find file for upgrading!"));
return;
}
// copying update
QString fileName = fileInfo.absoluteFilePath();
//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;
}
QStringList arguments ;
arguments << " /c" <<"c:\\temp\\upgradeTesting\\test.bat"<< fileName ;
QProcess *process = new QProcess( this );
process->start( cmdFile.absoluteFilePath(), arguments ) ;
if( !process->waitForStarted() )
{
QMessageBox::information(this, tr("Information"),
tr("Failed to start the process for upgrading!"));
return;
}
QMessageBox::information(this, tr("Information"),
tr("Please wait while system is upgrading .. click Ok to exit this box"));
qDebug() << fileName ;
process->waitForFinished() ;
qDebug() << process->readAllStandardOutput();
QMessageBox::information( this, tr( "Information" ),
tr( "Upgradation is successful.. Please restart the system") ) ;
process->deleteLater();
}
我编写了一个批处理脚本(.bat),它执行类似的命令
pscp -pw "lol" "%TARGET_UPDATE%" squire@"%TARGET_IP%":"%BASE_DIR%"/
通过批处理文件执行 bash 脚本如下是批处理文件中的命令
putty -pw "lol" -m test-update.sh squires@"%TARGET_IP%"
我什至尝试过类似的东西
C:\\Program Files\\putty.exe -pw "lol" -m test-update.sh squires@"%TARGET_IP%"
请各位大佬告诉我我哪里出错了?
感谢和问候,
山姆
【问题讨论】:
标签: qt bash batch-file