UNIX COMMANDS

#include 
main()
{
char str[10];
int pid;
pid=fork();
if(!pid)
{
printf("child process");
printf("enter the command");
scanf("%s",&str);
system(str)
printf("finished with child ");
}
else
wait();
retrun(0);
} 
output:-
child process:-
enter the command
ls -l


with this output i m just getting file names ...but i need ls -l --- lists files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.

Replies

  • Jayaram Reddy
    Jayaram Reddy
    Here in the command it will take only "ls" why because you are reading the string using scanf. It will read only one string here ls -l are two strings. So use "gets" function to read the string.....
    But here one warning will be there that u are reading a string using its address so it is better to use pointer declaration, not an array. But it is ignorable....😀

You are reading an archived discussion.

Related Posts

One of the leading Indian consumer electronics company, Micromax Informatics Limited, has announced the launch of its new affordable smartphone Canvas Xpress A99. Priced at Rs 6,999, the handset will...
Quote; Developers of medical technology should study how GPS continues to disrupt how people navigate from point A to point B, said Alan Greene, MD, chief medical officer of Scanadu...
Creating a photo realistic digital face is very difficult for any graphics designer. Well, there is a good news from researchers at Disney Research Zurich (DRZ). They have developed a...
Anyone having IS 2490 Part 1?Kindly upload
There are numerous rumors around the next Samsung flagship. Obviously it’ll be the Galaxy S6, since it is very unlikely that Samsung will stop its successful Galaxy flagship series. A...