Solved

Stuck with ls

Posted on 1998-07-03
2
461 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

635 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