• Tags
  • C

system() call not inheriting shell environment?

Latest response

Hi,

We have a piece of 'C' code that we've been using on our Oracle Linux servers for sometime without issue however, we're now trying to use it on our new Redhat Server and it's not working.
The code simply makes a system call to move a file between two directories.

Following is our original code that works on Oracle Linux:

command = "mv /home/useraccount/temp/filename.txt /home/useraccount/archive/newfilename.txt"
if (system(command) == 0) 
    log_output("File %s has been moved", filepntr->d_name);

However to get this to work on Redhat Linux we have to include the full path to the mv command thus:

command = "/usr/bin/mv /home/useraccount/temp/filename.txt /home/useraccount/archive/newfilename.txt"
if (system(command) == 0) 
    log_output("File %s has been moved", filepntr->d_name);

Can anyone please advise as to why on Redhat the PATH environment variable isn't inherited when we make the system() call as it is under Oracle Linux?

Thanks,

MikeT.

Responses