Reputation: 6178
How can someone recognise if he needs to put input parameters for an executable in C++.
What commands should you find in a code to know which parameters are needed?
For example if you need to run it like this: hello.exe test.txt. But you dont know it.
So you run the hello executable but it needs a text file next to it. How can someone recognise in the code that this kind of parameters are needed??
EDIT: my source code has main like this int main(int argc,char *argv[]) but what exactly can the arguments be?
The only place that the argc and argv appear is at this lines.
#ifdef PARALLEL
Test.CVodeInit_parallel(states,startTime,argc,argv);
#else
Test.CVodeInit_serial(states,startTime);
#endif
Upvotes: 1
Views: 1150
Reputation: 2009
For example - if someone runs your code like this:
hello.exe test.txt
then argc will be 2, argv[0] = "hello.exe", argv[1] = "test.txt"
but if they run the code like this:
hello.exe
then argc will be 1, argv[0] = "hello.exe"
Is that the question you are asking about? Basically argc is an integer, and tells you how many strings are in the argv array
Upvotes: 1
Reputation: 474336
There is no simple way to take a live executable and ask it what arguments it takes. Most EXEs that take arguments have a -h
or --help
or /h
or something similar that displays what arguments it takes. But outside of that, no.
From source code, you can kind of reconstruct its arguments. Many program use some GNU tool to parse arguments from argv
, so you'll need to be familiar with that to understand what it's doing. Boost.ProgramOptions is an alternative that some people use. And others just parse the arguments manually, so you have to walk the code and watch what it pulls out of argv
.
The only place that the argc and argv appear is at this lines.
Then you must look at the implementation of Test.CVodeInit_parallel
to know what arguments it takes.
Upvotes: 0
Reputation: 14692
parameters are passed to the program as parameters of the main
function, which should look like this:
int main(int argc, char** argv)
where argc
is the number of parameters and argv
is an array of strings containing the actual arguments.
So check in the code whether these parameters are handled.
NOTE: the main
function can also look like this:
int main()
which is legal but mean that the program does not expect, or handles, parameters.
Upvotes: 0
Reputation: 23560
You write "in the code" but you are asking about the ".exe". It is unclear whether you have access to the source-code or want to derive it from the raw binary.
In the former case you would have to take a look at the main()/WinMain()-function (or equivalent entry-point), the latter case would probably be impractical / too difficult as it involves disassembly and heuristics.
Upvotes: 0