Reputation: 703
What could possibly be wrong with this execl
statement? When I try to run it, the receiving executable complains that the argc
is less than 3. When I print the argv contents, I get the following:
argv[1] = -1076146944
argv[2] = 0
Despite the arguments consisting of:
numJoeysStr = 6
randomNumSeedStr = 7
execl("/path/to/executable", "numJoeysStr", "randNumSeedStr", (char *)0);
FWIW, I tried NULL in replace of (char *)0). That didn't make a difference.
Chris Jester-Young resolved my biggest issue, but now I get the following after placing in the function twice:
argv[1] = -1075725068
argv[2] = -1075725056
I tried dereferencing, by doing:
printf("argv[1] = %d\n", *argv[1]);
printf("argv[2] = %d\n", *argv[2]);
Only to receive the following:
argv[1] = 110
argv[2] = 114
When I expected:
argv[1] = 6
argv[2] = 7
For the final problem, it turns out that passing the variables into execl
without the quotes gave it the numbers I expected. I was somehow under the impression that all execl
arguments (aside from the last) must be in quotes, even the variables.
Upvotes: 1
Views: 361
Reputation: 223003
You actually need to specify "/path/to/executable"
twice. The first one is the program to execute, and the second one is the argv[0]
for the new process.
Upvotes: 4