Open multiple files with open() from stdin.PLEASE HELP

Open multiple files with open() from stdin.PLEASE HELP

Post by Mandell » Sun, 29 Mar 1998 04:00:00



Please help me.
Im having problems opening multiple files from stdin.
Mainly large files,(/usr/bin).

All I want to do is pipe ls from command line into program.

Here is test version of myprogram:

/*header files*/
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<ctype.h>

/*prototypes*/
int fd;

main(int argc,char *argv[])
{
 char file[80];
 int fd;

 while(fscanf(stdin,"%s",file) != EOF)
 {
  if ((fd=open(file,O_RDONLY))==-1)
   fprintf(stdout,"error opening file %s *** %d\n",file,fd);
  else
   fprintf(stdout,"ok opening file %s *** %d\n",file,fd);
  close(fd);
 }

 return 0;

Quote:}

**********************************

when I open files in my local directory(which contains small text files)
works
ok: #ls | myprogram

but any other directory, returns -1 when trying to open a file.
ls /usr/bin | myprogram  (cannot open files)

Please help,

Thank you very much.

 
 
 

Open multiple files with open() from stdin.PLEASE HELP

Post by Barry Margoli » Sun, 29 Mar 1998 04:00:00




>but any other directory, returns -1 when trying to open a file.
>ls /usr/bin | myprogram  (cannot open files)

When "ls /usr/bin" prints out "cat", your program will try to open a file
named "cat" rather than "/usr/bin/cat".  Since the filename doesn't have a
directory prefix, your program will look for it in the current directory,
but there's no file by that name in your directory.  Try:

find /usr/bin -type f -print | myprogram

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

 
 
 

Open multiple files with open() from stdin.PLEASE HELP

Post by Paul Kel » Sun, 29 Mar 1998 04:00:00




Quote:>Please help me.
>Im having problems opening multiple files from stdin.
>Mainly large files,(/usr/bin).

>All I want to do is pipe ls from command line into program.

Have you tried popen() ? also make sure you close any files you open
when done, or could could run out of file descriptors.

Paul

 
 
 

1. Help: What controls number of files a user can open (file open command)?

Group,

I have a script which analyzes certain source files (.c) and opens an
HTML file for
each source file in a separate directory. These HTML files have some
code coverage
(CFLOW) information.

I have a Tcl script that opens a C source file, analyzes it and then
opens a New HTML file and
dumps information into it.

When I run this Tcl script under my user ID, I am able to run the script
to completion. However,
if any other user (authorized to run the script), runs my script, Tcl
bails out with an error message
saying : Too many Open files !!

My question is why does this work with my user ID but not with other
user IDs ? Is there a parameter/
environment variable that controls the number of simultaneous open
files/file handles a given user
can have ? Is it shell dependant ? I use "zsh" whereas other users use
bash / ksh / csh etc.

I would really appreciate if someone could help me with this as this is
a long standing issue I am
trying to solve.

Thanks

Regards
Nishi

2. building php4 with apxs for apche 1.3.14 with gcc

3. OpenWin Filemgr: 'cannot open file: too many files open' ?

4. tape dump

5. Open File Manager (open file backup) for Linux?

6. Sun can't handle StarOffice

7. Finding the name of a file opened on stdin redirection

8. hercules 3D prophet 4000 + Suse 7.0

9. File open or not open ???

10. map a process open file to a open socket ?

11. Can't open a broadcast socket because there are too many open files?

12. File open or not open???

13. cannot open /dev/mem: too many open files??