Sponsored Content
Full Discussion: system() fails
Top Forums Programming system() fails Post 302220395 by jim mcnamara on Thursday 31st of July 2008 03:34:55 PM
Old 07-31-2008
ramen is telling you about 3-4 things.

The command run system() does not have stderr to redirect to without causing an error.
That is your error.

unlink() and remove() are how you delete files in UNIX/C. Not system(). try man unlink before you decide it is for removing what you seem to think a link might be. A link is a directory entry that points to an inode, by the way. That is usually an actual file.

Finally he is telling you that system() is a bad choice. Don't use it for things you can do in C. There are a lot of reasons for this: from security to performance, to 'why not just use shell instead of C?'

And next to last, you should be using the macros in sys/wait.h to test the return code of system() - you should consider: WIFEXITED(), WEXITSTATUS(), and so on. There are reasons for this, like the LSB of the return code, only, has meaning. You need to ignore the other bytes.

And last - don't you imagine that maybe all of the commands like: cp, mv, rm -- are written in C to start with? And that some of them are system calls, so that running them in C is an order of magnitude more efficient. By the way what system call do suppose rm uses? Hint: ramen named it.
 

10 More Discussions You Might Find Interesting

1. Programming

stat() fails!!! what can i do?

Hi all, I can not understand why my stat() function fails all the time when function tries to go recursevly. Someone suggested that it might be poiter problem. Please, look up my code at: www.donnelly.cc.ks.us/readdir_test.c. How can i solve this problem? Any suggestion are welcome! Thank you... (3 Replies)
Discussion started by: solvman
3 Replies

2. UNIX for Advanced & Expert Users

System Fails

Hi Exprts, There's a critical problem on one of the Workstations that the client reports every morning their system is down. It seems there's no power failure, as in the next startup the file systems are stable ,so i checked the "messages" file , the last line which i got before failure is :... (2 Replies)
Discussion started by: nikk
2 Replies

3. AIX

mkvg fails

# mkvg -y temp_vg hdisk5 0516-1254 mkvg: Changing the PVID in the ODM. 0516-1207 mkvg: An invalid physical volume ID been detected on hdisk5. 0516-862 mkvg: Unable to create volume group. ??? What do I do? AIX 4.3.3 I have seen something like this before but I don't remember the... (2 Replies)
Discussion started by: osee
2 Replies

4. Shell Programming and Scripting

Need to know why Perl fails.

Hello . Would really like to know why this code fails . I need to edit both the QUESNO : and <\p> tag at the same time . open(TEXT, "<20030211.txt") || die ("Cannot open the text files"); while (<TEXT>) { if ($_ =~ m/QUESNO :/) { if ($_ =~ m/<\/p>/) { print ($_); ... (0 Replies)
Discussion started by: whatsup
0 Replies

5. UNIX for Advanced & Expert Users

make fails...

Hi When im trying to do make --version and make --help in HP-UX it throws error Make: Unknown flag argument -. Stop. a soft link is present in this directory /usr/bin/make and hard link is in /usr/ccs/bin/make what could be the reason can any1 ..please tell me how to solve this... (1 Reply)
Discussion started by: vasanthan
1 Replies

6. UNIX for Advanced & Expert Users

why script fails sometime?

Hi, I am trying to run a shell script on solaris,some time it works fine and some times it fails unexpectedly. There is a script called "autostart.sh" which automatically starts the Application server but some times the script fails to strat the application server. can anyone tell me what... (10 Replies)
Discussion started by: tahir23
10 Replies

7. Solaris

smf fails to mount svc:/system/filesystem/usr:default

http://i44.tinypic.com/2cmq7vn.jpg Please help me on this issue i'm using solaris on vmware x86 even i runed fsck on root disk like 'fsck -Y /dev/rdsk/c0d0s0 ' but again after reboot it is going to maintanance mode reply soon (6 Replies)
Discussion started by: knl.sundeep
6 Replies

8. Programming

realloc() fails

Not sure in which forum to post this. I'm trying here, in Programming. I'm working on a PC with Intel Duo processor & 2GB of ram. OS is Ubuntu 10.04. I'm having problems with a C++ program that makes extensive use of realloc(). It happens that as soon as the overall memory allocated(OS +... (14 Replies)
Discussion started by: mamboknave
14 Replies

9. HP-UX

shl_load fails

Hi, I have written a simple program of 2 lines in C to load a library using SHL_LOAD. It fails with error "/usr/lib/hpux32/dld.so: Unable to find library 'xyz.sl'. Load failure for library , ERRNO = 2" Shlib_PATH,LD_LIBRARY_PATH,PATH,LD_PRELOAD are set correctly and library exists on the... (0 Replies)
Discussion started by: ashwinichavan
0 Replies

10. AIX

Cloning a system via mksysb backup from one system and restore to new system

Hello All, I am trying to clone an entire AIX virtual machine to a new virtual machine including all partitions and OS.Can anyone help me on the procedure to follow? I am not really sure on how it can be done.Thanks in advance. Please use CODE tags for sample input, sample output, and for code... (4 Replies)
Discussion started by: gull05
4 Replies
UNLINK(2)							System Calls Manual							 UNLINK(2)

NAME
unlink - remove directory entry SYNOPSIS
#include <unistd.h> int unlink(const char *path) DESCRIPTION
Unlink removes the entry for the file path from its directory. If this entry was the last link to the file, and no process has the file open, then all resources associated with the file are reclaimed. If, however, the file was open in any process, the actual resource recla- mation is delayed until it is closed, even though the directory entry has disappeared. RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
The unlink succeeds unless: [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] The path name exceeds PATH_MAX characters. [ENOENT] The named file does not exist. [EACCES] Search permission is denied for a component of the path prefix. [EACCES] Write permission is denied on the directory containing the link to be removed. [ELOOP] Too many symbolic links were encountered in translating the pathname. (Minix-vmd) [EPERM] The named file is a directory. [EPERM] The directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID. (Minix-vmd) [EBUSY] The entry to be unlinked is the mount point for a mounted file system. [EIO] An I/O error occurred while deleting the directory entry or deallocating the inode. [EROFS] The named file resides on a read-only file system. [EFAULT] Path points outside the process's allocated address space. SEE ALSO
close(2), link(2), rmdir(2). 4th Berkeley Distribution May 22, 1985 UNLINK(2)
All times are GMT -4. The time now is 03:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy