shell commands execution in c program without system function
Dear All:
i require to use execute shell commands in c program without the use of "system()" function. As it was strictly warned us to take that advantage. can any one assist me any Header/Library with some group of functions which does exactly as it's done by System function. Thanx in Advance |
Homework?
fork + execl(and co) are your friends... |
This does sound like homework. That gives me license for a little RTFM. Read the notes in the man 3 system manpage. It explains when system() can be dangerous and what to use instead.
|
Dear jschiwal,
i read MAN page now for specific commands which i entered into my program.. Actually what i want to know is that, As i write date on Terminal,it gives current system date while using the same in C-Program we use system function.But Sir told not to use it.Don't know why he told that. he Exactly told us to find some functions/libraries which will do as system does for you. In case of DATE,find a function which will return current date of your system.. so,now can you assist please. |
For a quickstart: time(2) + ctime(3)
Advanced usage: time(2) + localtime_r(3) + strftime(3) Note: the number after the name refers to the manual sections, eg: man 2 time man 3 ctime etc |
Quote:
|
Dear jschiwal,
i went through MAN page of following commands->cat,ps,top,df,more i could not find any function suggestion in here. will you please view MAN for above few commands and post in here,so that i could get some rough idea for further commands. Actually i am very new in reading those system manuals and all.the whole manual is beyond my understanding. |
As mentioned above, it is time, ctime, localtime_r and strftime.
Note: Tha manpage of system explains how can you use fork+exec instead; but just to get the current date/time you don't have to call external programs at all. |
I think you may find popen a good choice.
|
Function popen, to get the current date? How?
Quote:
|
popen in answer to the original question.
|
Thanks all of you..
I tried with fork but execution speed and Robustness were primary concern. let me tell you easy way,might be helpfull for others. I tried with "EditLine Library",& have full unbreakable shell,Actually it Interfaces between our c program and System command functions. |
All times are GMT -5. The time now is 03:38 PM. |