Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Command line arguments working in terminal but not through IDE
Forum Updated to NodeBB v4.3 + New Features

Command line arguments working in terminal but not through IDE

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
5 Posts 3 Posters 174 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.
  • A Offline
    A Offline
    A123
    wrote on last edited by
    #1

    Hello I'm trying to run a program through QT Creator that fails through the IDE due to 'Wrong number of arguments given to' but runs fine in the terminal with the same working directory.

    The command I am using in both terminal and in the command line arguments box is in the form

    ./SampleProgram modelfile.model Initiationfile.init paramfile > resultsFile
    

    The working directory and executable locations seem to be right And I've been able to run this program through the IDE before.
    I'm using Qt Creator version 14.0.2 and running through Linux Mint.

    JonBJ 1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      Hi @A123,

      I don't believe the program itself should be given as an argument in the IDE. ie try:

      modelfile.model Initiationfile.init paramfile > resultsFile
      

      Failing that, update your main() to debug-log all of its arguments, to see what it sees.

      Cheers.

      1 Reply Last reply
      2
      • A A123

        Hello I'm trying to run a program through QT Creator that fails through the IDE due to 'Wrong number of arguments given to' but runs fine in the terminal with the same working directory.

        The command I am using in both terminal and in the command line arguments box is in the form

        ./SampleProgram modelfile.model Initiationfile.init paramfile > resultsFile
        

        The working directory and executable locations seem to be right And I've been able to run this program through the IDE before.
        I'm using Qt Creator version 14.0.2 and running through Linux Mint.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @A123 said in Command line arguments working in terminal but not through IDE:

        ./SampleProgram modelfile.model Initiationfile.init paramfile > resultsFile

        This command has an output redirection symbol, the >. That is not handled by your SampleProgram. When you run it from "the command line" you actually mean from a shell (e.g. bash or cmd.exe), and it is that which sees the > resultsFile, opens the file for output and passes the open file descriptor on to SampleProgram.

        Unless Creator either (a) runs your program through bash, which I strongly doubt (e.g. you could not then debug your program) or (b) handles >, >>, < etc. itself just like the shell, stripping them off and dealing with it, which I suspect it does not(?), the end result will be that your program is called with 5 arguments, and perhaps it only accepts 3 and hence 'Wrong number of arguments given to' ....

        You could simulate what (I think) is happening from Creator on your "command line " by testing that with

        modelfile.model Initiationfile.init paramfile '>' resultsFile
        

        Does that then give same message?

        Start by removing the > resultsFile from the arguments in Creator. If that works figure your options if you still need the output to be redirected each time.

        A 1 Reply Last reply
        1
        • A A123 has marked this topic as solved on
        • JonBJ JonB

          @A123 said in Command line arguments working in terminal but not through IDE:

          ./SampleProgram modelfile.model Initiationfile.init paramfile > resultsFile

          This command has an output redirection symbol, the >. That is not handled by your SampleProgram. When you run it from "the command line" you actually mean from a shell (e.g. bash or cmd.exe), and it is that which sees the > resultsFile, opens the file for output and passes the open file descriptor on to SampleProgram.

          Unless Creator either (a) runs your program through bash, which I strongly doubt (e.g. you could not then debug your program) or (b) handles >, >>, < etc. itself just like the shell, stripping them off and dealing with it, which I suspect it does not(?), the end result will be that your program is called with 5 arguments, and perhaps it only accepts 3 and hence 'Wrong number of arguments given to' ....

          You could simulate what (I think) is happening from Creator on your "command line " by testing that with

          modelfile.model Initiationfile.init paramfile '>' resultsFile
          

          Does that then give same message?

          Start by removing the > resultsFile from the arguments in Creator. If that works figure your options if you still need the output to be redirected each time.

          A Offline
          A Offline
          A123
          wrote on last edited by
          #4

          @JonB The problem was the program name apparently which was weird because I remember running it in the IDE with the name included. Maybe it was because this was an earlier version.

          JonBJ 1 Reply Last reply
          0
          • A A123

            @JonB The problem was the program name apparently which was weird because I remember running it in the IDE with the name included. Maybe it was because this was an earlier version.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @A123
            So the "arguments" box does let you include > file? I am surprised, interesting.

            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