![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirecting OUTPUT | Chanakya.m | Shell Programming and Scripting | 1 | 08-13-2007 04:27 PM |
| redirecting the output of aspell | leekb | UNIX for Advanced & Expert Users | 6 | 07-10-2006 05:50 AM |
| Redirecting the startup output | blakmk | UNIX for Dummies Questions & Answers | 3 | 10-28-2003 07:22 AM |
| Redirecting output to TCP port | mscomms | UNIX for Dummies Questions & Answers | 1 | 09-30-2003 10:51 PM |
| Redirecting output to multiple log files? | darthur | UNIX for Dummies Questions & Answers | 3 | 01-15-2002 12:54 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
execl() + redirecting output to text files
Im currently using execl() to run the ls command and redirect the output to a text file. Unfortunately, when I check the text file, no information has been written to it.
I am calling execl() with the ls command like this Code:
execl( "/bin/ls" , "-al" , '>' , "dirlist.txt" ,(char *) 0 ); |
|
||||
|
The problem is: you are giving ls something that actually is the shell's responsability, and that thing is output redirection. Since there is no shell involved in your program, you should perform the redirection of the output by yourself, that is, your program should do the shells's work, first by openning a new file and them redirecting its standard output and standard error to the new file descriptor using the dup2(2) function.
PHP Code:
|
|
||||
|
Hi guys
I ended up using system() instead and it resolved my probs (although I had to use a lot of strcmp() calls to create the command ) of redirecting shell output to a file. Another reason why I chose to reject execl() in favour of system() was because I didn't really understand the manual description of it too well (apart from its purpose of course)pflynn, thanks for your suggestion. Just a question (which may be a bit stupid so bear with me). The standard output is the place where all output of any c program is directed to (i.e. the place where all printf() calls have the text displayed ) ? |
|
||||
|
Quote:
Quote:
Quote:
More information on the standard streams: Standard streams Standard streams - Wikipedia, the free encyclopedia |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|