Why can't we change directories through system() system call in Linux?

前端 未结 3 1194
傲寒
傲寒 2021-01-07 09:30
system (\"cd ..\");

This doesn\'t produce any error but also doesn\'t do anything meaningful. Why?

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 09:54

    system runs the command you passed it in a different process (in a subshell). That subshell changes directories and promptly exits.

    That's all perfectly valid, but perfectly useless. Use chdir to change your working directory.

提交回复
热议问题