AFAIK, by calling system()
function call, it will execute the command
by calling /bin/sh -c
and will return the exit status. The next call to system()
will invoke another /bin/sh -c
.
So, basically, for each call, a new child shell is used. Hence, you cannot expect the result of the first call to be preserved [persistent] in the second call. Your current process directory will not be affected. Next call to system()
will consider the old current process directory itself.
You can try providing both the commands to be executed in a single call to system()
, by joining them with &&
or ;