io - How do I send input to a process in C? -


i'm trying run git push c:

system("git push"); 

and when asks for

username: password: 

i want give username, , github auth token. how accomplish this? i've tried around solution, can't seem wording right when google problem. note have username , auth token stored in char*'s:

char *username = "whatever"; char *token = "whatever"; system("git push"); 

it impossible send input data process if created using system(char *command); (or maybe possible, think hard), need create new process popen(const char *command, const char *type);. (popen documentation here). little exmaple wrote:

#include <stdio.h> #include <stdlib.h>  int main(int argc, char **argv) {     char username[] = "something";     char password[] = "something";     file *pf; // file descriptor of git process      pf = popen("git push", "w"); // create git process in write mode      if (!pf) {         printf("process couldn't created!");         return 1;     }      // send username , password (and '\n' char too) git process     fputs(username, pf);     fputs(password, pf);     pclose(pf); // close git process      return 0; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -