PDA

View Full Version : Execute a .bat file with argument using QScriptEngine in Qt



anbu01
7th February 2016, 08:57
I have a .exe file with a change directory command as follows:-

set test="C:\Program Files"
cd /d %test%

so i need to execute this .bat file using QScriptEngine.I know this can be achieved through QProcess.But i need to execute using QScriptEngine.I need to set the variable "test" to engine first and then i need to execute the command.On seeing the docs i used the following code:-

QScriptEngine engine;
QScriptValue result = engine.evaluate("D:/Moses/test.bat");
qDebug() << result.isError();

The out here is true.So some how first i need to set variable test to engine and then evaluate the .bat file.

anda_skoa
7th February 2016, 10:33
QScriptEngine is a JavaScript engine, not a Windows Batch interpreter
It evaluates JavaScript, not batch files.

As you have already discovered, the correct way to run an external program is through QProcess.

Check the QtScript documentation on how to expose C++ to the script side.

Cheers,
_

anbu01
7th February 2016, 11:28
@anda_skoa:thanks