Qt 如果目录包含exe或msi文件,请使用命令行参数启动它
此应用程序仅适用于Windows。它将在QT Creator中构建。我使用Qt 如果目录包含exe或msi文件,请使用命令行参数启动它,qt,file,command,switch-statement,exe,Qt,File,Command,Switch Statement,Exe,此应用程序仅适用于Windows。它将在QT Creator中构建。我使用7zip.exe作为示例,因为它非常快速且易于测试。 我有一个目录列表,每个目录都包含一个*.exe或*.msi文件。 在按钮上单击()在Qt中,我想转到指定的单个目录,并启动该目录中的任何可执行文件或*.msi文件。*.exe或*.msi文件名将不时更改,否则我可以简单地使用系统命令 系统(“启动7zip\7zip.exe/S”) 我的问题是,我想运行一个通配符,例如*.exe或*.msi,并在其中添加一个命令行开关 现
7zip.exe
作为示例,因为它非常快速且易于测试。
我有一个目录列表,每个目录都包含一个*.exe
或*.msi
文件。
在按钮上单击()
在Qt
中,我想转到指定的单个目录,并启动该目录中的任何可执行文件或*.msi
文件。*.exe
或*.msi
文件名将不时更改,否则我可以简单地使用系统命令
系统(“启动7zip\7zip.exe/S”)
我的问题是,我想运行一个通配符,例如*.exe
或*.msi
,并在其中添加一个命令行开关
现在我想在path中执行单个文件,并添加参数/S
我让它在批处理文件中工作:
for /F %%a in ('dir /b 7zip\*.exe') do SET app1=%%~na
%app1% /S
但是我不确定如何在Qt
中实现它
谢谢您想使用两件事:迭代系统中的目录和启动带有参数的外部进程。谢谢AlexanderVX
它们正是我们所需要的。我相信有很多方法可以让它更优雅,但它正是我现在想要它做的
void MainWindow::on_pushButton_clicked()
{
//set initial directory to search for the exe file
QDirIterator file("7zip", QDirIterator::Subdirectories);
while (file.hasNext())
{
file.next();
QString prog = file.fileName(); //get actual filename
QStringList cswitch;
cswitch << "/S"; //create the command switch to use when running the exe
QProcess *install = new QProcess(this); // create new process called install
QDir::setCurrent("7zip"); //set working directory needed to install the exe
install->start(prog, cswitch); //launch the exe with the desired command switch
}
}
void主窗口::在按钮上点击()
{
//设置初始目录以搜索exe文件
QDirIterator文件(“7zip”,QDirIterator::子目录);
while(file.hasNext())
{
file.next();
QString prog=file.fileName();//获取实际文件名
QStringList开关;
cswitch start(prog,cswitch);//使用所需的命令开关启动exe
}
}