Running the following lines of code and running into issues that I am not sure about. The main idea is for a user to enter in an inode to be searched. Once found, the file name associated with that inode is printed, then the command "stat" is ran on that file name to produce info on that file.
#define COMMAND_LEN 1024
#define DATA_SIZE 1024
int main(int argc, char **argv) {
FILE *pf;
char command[COMMAND_LEN];
char data[DATA_SIZE];
char inode_data[DATA_SIZE];
int iNode;
printf("Enter inode: ");
scanf(argv[0], iNode);
sprintf(command, "find -inum %i -type f", iNode);
pf = popen(command, "r");
if(!pf){
fprintf(stderr, "Could not open pipe for outlet.\n");
return;
}
fgets(data, DATA_SIZE, pf);
fprintf(stdout, "%s\n", data);
sprintf(command, "stat %s", data);
pf = popen(command, "r");
fgets(inode_data, DATA_SIZE, pf);
fprintf(stdout, "%s\n", inode_data);
if (pclose(pf) != 0)
fprintf(stderr, "Error: Failed to close command stream!\n");
Return 0;
}
Once I compile, run, and enter an inode number, I get the following:
Enter inode: 148869
stat: missing operand
Try 'stat --help' for more information.
Error: Failed to close command stream!
Received useful help from perivous question post Save information from sprintf to a variable