[Tutor] File copying - best way?

alan.gauld@bt.com alan.gauld@bt.com
Mon, 6 Aug 2001 10:51:24 +0100


> On Sun, Aug 05, 2001 at 10:46:55PM +0100, alan.gauld@bt.com wrote:
> > No. The reason being that in Unix 'ls' findng no files is 
> > NOT an error. 

> $ ls
> [snip]
> $ echo "$?"
> 0
> $ ls ./*.jpg
> ls: ./*.jpg: Datei oder Verzeichnis nicht gefunden
> $ echo "$?"
> 1
> It sets errno on my System

Interesting - back to the terminal to try again....

Ah! I was testing with a malformed C program:

#include <stdio.h>
#include "errno.h"
#include "stdlib.h" 
  
void main(){   
    // this works   
    system("ls /etc");   
    perror("Test:");   

    // this doesn't   
    system("ls /frutty");   
    perror("Test:");
}

I should of course have been testing the return value of system().

    status = system("ls /etc/fruuty");
    printf("status = %d\n", status);

errno held the result of system(), not the result of the command 
executed by system() - oops!

Alan G.