Solved

Stuck with ls

Posted on 1998-07-03
2
444 Views
Last Modified: 2010-04-21
I need to list all the files in a directory so my call in a C program is system(syscmd)
where syscmd is "ls -l /tmp/receive/*.* > /tmp/receivelist"
however if there are no files in the directory receive my command fails as ls /tmp/receive/*.* returns no files found.
Any suggestions how to stop the error message and determine a list of files in a directory using a wildcard pattern?
0
Comment
Question by:datavalue
2 Comments
 

Accepted Solution

by:
singlep2 earned 80 total points
ID: 2008434
As you are using ls -l I shall assume you are running your C program in a UNIX environment.

I shall also assume that you are specifically using *.* because you don't want to include the receivelist file (or any other file containing a ".") in your list of files.

To stop the ls command returning the std err message use:

ls -l /tmp/receive/*.* >/tmp/receivelist 2>/dev/null

The 2 is for std err output which in this case is redirected to the UNIX bit bucket in the sky -> /dev/null.

Hope this is what you want.

Paul Singleton
0
 
LVL 3

Expert Comment

by:braveheart
ID: 2008435
If you are executing the command in the C-shell, i.e. if your normal login shell is the C-shell (or tcsh) you should set the shell (not envt.) variable "nonomatch" either in ~/.cshrc or as part of the syscmd. This should suppress the error message and status code so that the generated output will be empty.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now