I have a curl command:
curl -c cookies.txt -b cookies.txt -k https://www.example.com/ajaxauth/login -d 'identity=email@example.com&password=pa$$w0rd&query=https://example.com/data/format/json' > ~/Documents/.../myProject/bin/data/myData.json"
that
- logs in to an API,
- manages cookies,
- fetches a dataset and saves to local file.
I have it in a char array and was sending to the system()
command, but due to the dangers of passing vars (email and password) to system()
, I must use exec()
instead. I'm not familiar with this command and the documentation is confusing me. So my questions:
Is this even possible or do I have to go back and break up my command into individual calls or even multiple exec calls?
I assume I should be using an execv version because I'm passing in a whole character array, is this correct?
Many different sources say the first argument for an
exec()
command must be an executable file. For example, "The first argument, by convention, should point to the file name associated with the file being executed." How does a curl command count as such?Why is this person passing
(char *) 0
as the last argument?
This is what I have so far:
int pid = fork();
switch(pid){
case -1:{
perror("fork"); // via https://stackoverflow.com/q/2329640/1757149
_exit(EXIT_FAILURE);
break;
}
case 0:{ // child process
//execv(cmd, ???);
break;
}
default:{ // parent process
break;
}
}
Note that I can't use libcurl. Any help appreciated!