Results 1 to 3 of 3

Thread: Execute a .bat file with argument using QScriptEngine in Qt

  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Execute a .bat file with argument using QScriptEngine in Qt

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Execute a .bat file with argument using QScriptEngine in Qt

    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,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Execute a .bat file with argument using QScriptEngine in Qt

    @anda_skoa:thanks

Similar Threads

  1. Replies: 3
    Last Post: 27th February 2014, 12:41
  2. How to execute my .css file in Qt?
    By harish in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2011, 11:12
  3. Replies: 3
    Last Post: 28th February 2010, 08:10
  4. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 17:04
  5. How to execute an exe file from Qt application
    By maveric in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2008, 10:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.