要从.bat文件执行bash脚本,QT应用程序将调用.bat文件

要从.bat文件执行bash脚本,QT应用程序将调用.bat文件,qt,bash,batch-file,Qt,Bash,Batch File,我需要有关从批处理脚本(.bat)执行bash脚本的帮助,批处理脚本是由Windows内部的Qt应用程序调用的 问题概述:我需要通过Qt应用程序将文件从Windows传输到Linux box,并在Linux内部运行bash脚本以执行一些命令 到目前为止我所做的:我可以通过Qt应用程序成功地将文件从windows传输到Linux box。Qt应用程序调用传输文件的批处理文件 范例 void Qt_intro101::on_file_upgrade_clicked() { QFileI

我需要有关从批处理脚本(.bat)执行bash脚本的帮助,批处理脚本是由Windows内部的Qt应用程序调用的

问题概述:我需要通过Qt应用程序将文件从Windows传输到Linux box,并在Linux内部运行bash脚本以执行一些命令

到目前为止我所做的:我可以通过Qt应用程序成功地将文件从windows传输到Linux box。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();

  }
 putty.exe -pw "lol" -m C:\\temp\\upgradingTest\\test-update.sh squires@"%TARGET_IP%"
下面是批处理文件中的命令,用于通过批处理文件执行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%"
你们能告诉我我哪里出错了吗

感谢和问候,

Sam

每次运行时不能调用
waitforstart()
两次。如果
waitForStarted()
返回false,则表示从方法执行返回。因此,在
之后,如果(!waitForStarted()
您的进程正在运行。

在花费了许多小时之后,我意识到我需要在批处理脚本中为Qt提供完整的路径名来执行它。没有Qt,它可以正常工作,但是如果我想通过Qt app运行批处理文件,那么我想我需要为bash脚本提供完全限定的路径名。 范例

 putty.exe -pw "lol" -m C:\\temp\\upgradingTest\\test-update.sh squires@"%TARGET_IP%"
而不是

   putty -pw "lol" -m test-update.sh squires@"%TARGET_IP%"

我认为使用QProcess::execute(QString cmdstring)更容易 然后,还可以将参数传递给批处理文件本身

test.cpp

QFileInfo cmdFile( "C:\\Windows\\system32\\cmd.exe");
QProcess *process = new QProcess( this );
process->execute(cmdFile.absoluteFilePath() + " /c helloparam.bat \"my param\"  ");
process->waitForFinished() ;
qDebug() << process->readAllStandardOutput();

信息:要在IDE中测试这一点,请让舒尔确认您正在从发布文件夹运行application.exe,并且批处理文件也在该文件夹中

是的,您是对的。我忘了更改代码。我现在将更改代码。但在花费数小时后,它仍然无法运行,我意识到我需要在批处理中提供完整的路径名如果没有Qt,它可以正常工作,但如果我想通过Qt应用程序运行批处理文件,我想我需要给出bash脚本的完全限定路径名
@echo off
echo hello %1