I am trying to port a Korn shell program across to C on a Unix platform.
As part of this program, I need to be able to change the working directory within the C program. I have found the getenv/putenv functions according to the Wrox Beginning Linix programming book.
Whilst I understand that any changes to the Unix environment made within the code will not be seen by the calling Unix process, I have included a call to the system function in order to get the (intended to be the changed) directory - but this program just reports the same directory as when the program started?
Can someone explain what I am doing wrong/or mis understanding.
Below appears the code in question:
#include <stddef.h>
#include <stdlib.h>
extern char **environ;
main (int argc, char *argv[])
{
int RCODE;
RCODE=putenv("PWD=/tmp"
;
system("pwd"
;
if (RCODE != 0)
return (-1);
else
return 0;
}
Thanks
Andy
As part of this program, I need to be able to change the working directory within the C program. I have found the getenv/putenv functions according to the Wrox Beginning Linix programming book.
Whilst I understand that any changes to the Unix environment made within the code will not be seen by the calling Unix process, I have included a call to the system function in order to get the (intended to be the changed) directory - but this program just reports the same directory as when the program started?
Can someone explain what I am doing wrong/or mis understanding.
Below appears the code in question:
#include <stddef.h>
#include <stdlib.h>
extern char **environ;
main (int argc, char *argv[])
{
int RCODE;
RCODE=putenv("PWD=/tmp"
system("pwd"
if (RCODE != 0)
return (-1);
else
return 0;
}
Thanks
Andy