I use the execl() function with that call:
execl("/localhome/globususer/mandel", "-b", xmin, xmax, ymin, ymax, "-f", name, (char*)NULL);
All the xmin, xmax, ymin, ymax are initialized by:
sprintf(xmin, "%f", (double)(XPOS - realmargin));
sprintf(xmax, "%f", (double)(XPOS + realmargin));
sprintf(ymin, "%f", (double)(YPOS - realmargin));
sprintf(ymax, "%f", (double)(YPOS + realmargin));
In the targeted program (/localhome/globususer/mandel), xmin and ymin are detected as options since they are negative numbers.
So getopt() detects “-0” on their values, and raises an error.
However, a direct call from the command line such as:
./mandel -b -0.452902 0.456189 0.367922 1.277013 -f /localhome/globususer/mandel.ppm
is correctly understood by the program.
Does anybody have any idea?
You’ re using
execl()incorrectly. You should setarg0to the name of the executable:From the man page:
When
mandelrunsgetopt()with your original argument list, it skips over the-b(since it’s inargv[0], and it thinks that’s the executable path name), and therefore starts parsing the args with the number (-0.452902in your example) instead of the-b. That makes it interpret the-0as an option, and you’re out of luck.