Command line arguments working in terminal but not through IDE
-
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. -
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.
-
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.@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 yourSampleProgram
. When you run it from "the command line" you actually mean from a shell (e.g.bash
orcmd.exe
), and it is that which sees the> resultsFile
, opens the file for output and passes the open file descriptor on toSampleProgram
.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. -
-
@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 yourSampleProgram
. When you run it from "the command line" you actually mean from a shell (e.g.bash
orcmd.exe
), and it is that which sees the> resultsFile
, opens the file for output and passes the open file descriptor on toSampleProgram
.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. -
@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.