Home > Mobile >  [question] QProcess: : startDetached open bat file a flash problem
[question] QProcess: : startDetached open bat file a flash problem

Time:10-08

Project need to use QT application open another batch file (bat), and to stay in the console interface, effect and manual double-click to open the same line,

When I use QProcess: : startDetached opened more strange problems:

1. When the bat path there is no left parenthesis "(" , with or without blanks can open a console;
2. When the bat path there left parenthesis "(" , and existence space can open a console;
3. When the bat path there left parenthesis "(" , and there is no Spaces console a flash,

Procedure is as follows:
 
//a QString runPath="D: \ \ test \ \ test bat".//console open success
//a QString runPath="D: \ \ test (test \ \ test. Bat";//console open success
//a QString runPath="D: \ \ test (test \ \ test. Bat";//console flashes a
QFileInfo exeFile (runPath);
If (exeFile isFile ())
{
QString workDir=exeFile. AbsolutePath (). The replace ("/", "\ ");
Qint64 pid=0;

QDebug () & lt; QDebug () & lt; Bool pass=QProcess: : startDetached (runPath, QStringList (), workDir, & amp; Pid);
if (! Pass)//return true
{
QDebug () & lt; <"Fail".
return ;
}
}
return;


Tried to open the bat file with system, found a parenthesized will also be a flash, bother god,,,

Have a great god encountered similar problems?

CodePudding user response:

The test with the test. The bat content is as follows:
 
Echo "test bat file
"Pause

CodePudding user response:

CodePudding user response:

No one encountered this problem?

CodePudding user response:

Direct call CMD can

QString runPath="C: \ \ Windows \ \ System32 \ \ CMD exe";
The QStringList SSS;
SSS & lt; <"/k" & lt; <"D: \ \ test \ \ test bat".
Bool pass=QProcess: : startDetached (runPath, SSS);

CodePudding user response:

Before and after another path in the blank space need quotes,

QString runPath="" "D: \ \ test (test \ \ test. The bat " "

CodePudding user response:


If it is a normal path by which way is no problem, I the above problem is a path with a left parenthesis has the problem, such as:
RunPath="D: \ \ test \ \ test (test). The bat".

reference 4 floor xh286286 response:
direct call CMD can

QString runPath="C: \ \ Windows \ \ System32 \ \ CMD exe";
The QStringList SSS;
SSS & lt; <"/k" & lt; <"D: \ \ test \ \ test bat".
Bool pass=QProcess: : startDetached (runPath, SSS);

CodePudding user response:

Meet the same problem, use startDetached want to turn on the console interface, the official document said after 5.8, startDetached no longer open a console interface, with an example in
That can open a console interface but tried not
QProcess p;
P. etProgram (" CMD. Exe ");
P. etArguments ({"/k ", "echo", "Hello from Qt!" });
P. etCreateProcessArgumentsModifier ([] (QProcess: : CreateProcessArguments * args) {
The args - & gt; Flags & amp;=~ CREATE_NO_WINDOW;
});
P. tartDetached ();
https://bugreports.qt.io/browse/QTBUG-57687
The building Lord, please solve! Inquire of
(no water, the administrator don't deleted)
  •  Tags:  
  • Qt
  • Related