Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Execute java with Qt QProcess in Windows OS
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Execute java with Qt QProcess in Windows OS

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 7.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lucarma
    wrote on last edited by
    #1

    Hi all, i'm a noob in Qt programming. As title say, I'm trying to execute a java downloaded executable jar with my application, on windows os.. the only way I found is using QConnet and lauch a file .bat.

    In the file myFile.bat there's:

    java -jar dwnUtility.jar -input %1 -output %2 -quality %3

    In cpp I use

    @proc->start("D:\Work\myAppDir\myFile.bat", args);@

    This way works... but if use:

    @proc->start("C:\Windows\System32\java.exe", QStringList() << "-jar dwnUtility.jar" << "-input D:\Work\Qt_prj\file1.swf" << "-output D:\Work\Qt_prj\file2.swf" << "-quality 0.5");
    @

    and show the output with

    @
    connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(rightMessage()) );
    connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()) );
    @

    I obtain this error msg

    "Could not create the Java virtual machine.
    Unrecognized option: - jar dwnUtility.jar"

    Where I wrong? The .jar app compress all images present in file1 and make the file2 with the elaborate images

    I'd prefer use the proc without call the file .bat... but in this way works.
    Any idea?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What is the space between the - and the jar doing in your argument?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        delete the space between the dash and jar (make "- jar" to "-jar"). And you also need to add the arguments to the switches separately:

        @
        QStringList args;
        args << "-jar" << dwnUtility.jar";
        args << "-input" << "D:\Work\Qt_prj\file1.swf";
        args << "-output" << "D:\Work\Qt_prj\file2.swf";
        args << "-quality 0.5";

        proc->start("C:\Windows\System32\java.exe", args);
        @

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lucarma
          wrote on last edited by
          #4

          isn't in code.. a cut n' paste error while writing the post :(

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            I think you might even need to separate the quality argument into:
            @
            args << "-quality" << "0.5";
            @
            but I am not sure.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lucarma
              wrote on last edited by
              #6

              ok... in this way works fine

              thanks a loot :)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lucarma
                wrote on last edited by
                #7

                bq. I think you might even need to separate the quality argument into:
                1
                args << "-quality" << "0.5";
                but I am not sure.

                Works in both manners

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  ok, thanks. That's why I said I was not sure. Sometimes, the rules as to what goes where for argument lists for QProcess are not completely clear to me.

                  Edit: I noticed this comment in the docs:
                  [quote]Windows: Arguments that contain spaces are wrapped in quotes.[/quote]
                  That would mean that your last argument would become wrapped in quotes if you run it on windows, and I doubt that works ok. So, for safety, I would use the two-argument form.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [quote author="Andre" date="1314181153"]ok, thanks. That's why I said I was not sure. Sometimes, the rules as to what goes where for argument lists for QProcess are not completely clear to me. [/quote]

                    As a rule of thumb:
                    Everything that you can put together into quotation marks on a shell goes into one element of the string list.

                    Something like

                    @
                    java -jar blubb.jar
                    @

                    Consists of two arguments: the "-jar" "switch" and the "blubb.jar" argument to it. If you had put it into one string like this:

                    @
                    args << "-jar blubb.jar"
                    @

                    You would have a single "switch" "-jar blubb.jar" without an argument :)

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lucarma
                      wrote on last edited by
                      #10

                      if I use

                      @args << "-jar D:\Work\Reducer\reducer.jar";@

                      i have this error msg

                      Could not create the Java virtual machine.
                      Unrecognized option: -jar D:\Work\Reducer\reducer.jar

                      but the error isn’t when use the two element separated… why?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        Because it is treated as one single argument. Actually you need two arguments (the -jar and the list of jars).

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved