Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stuck with ls

Posted on 1998-07-03
2
Medium Priority
?
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
singlep2 earned 160 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

704 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