简体   繁体   English

QT批处理文件未执行。

[英]QT batch file not executing.

I have a multi-line batch file created using the following: 我有一个使用以下内容创建的多行批处理文件:

QFile file("C:/temp_exec.bat");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << cmd;
out << "\n";
out << cmd_alt;
file.close();

Where cmd and cmd_alts are legitimate multi-line batch commands. 其中cmd和cmd_alts是合法的多行批处理命令。 The created file executes fine with double click inside Windows, but through QT, it never executes. 在Windows中双击创建的文件可以很好地执行,但是通过QT,它永远不会执行。

I've tried literally all that there's available, and this was my latest attempt, 我已经尝试了所有可用的方法,这是我最近的尝试,

QProcess p;
p.setWorkingDirectory("C:/");
p.execute("temp_exec.bat");
p.waitForFinished();

Which works fine under the Qt Creator, but in a standalone executable (inside a folder with all the required Qt DLL's), nothing happens. 在Qt Creator下可以正常工作,但在独立的可执行文件(包含所有必需的Qt DLL的文件夹中)中,什么都没有发生。 CMD shell just opens and closes like nothing's happened. CMD外壳就像什么都没有发生一样打开和关闭。

Here's what's created inside temp_exec.bat: 这是在temp_exec.bat内部创建的:

cd /d "Z:\FRONT 2" & for %%i in (*) do move /Y "%%i" "Z:\2005\050016"
cd /d "Z:\FRONT 2" & for /d %%i in (*) do ROBOCOPY /E /IS /MOVE "%%i" "Z:\2005\050016"

Which If double click and run inside Windows it's OKAY, but through Qt, it's NOT. 如果双击并在Windows内运行可以,但是通过Qt可以。

I don't get why the framework doesn't explain WHY through QProcess STRANGE things happen. 我不明白为什么框架无法通过QProcess STRANGE解释为什么会发生这种情况。

Any ideas? 有任何想法吗? Help? 救命? Thanks. 谢谢。

nvm solved it. nvm解决了它。 Used p.startDetached() 使用p.startDetached()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM