perl 反引号不适用于 cd。为什么?
perl backticks not working for cd. Why?
我在 win7 上使用 AS perl。
print `cd \\ `; # does nothing, says nothing
同 qx()
print `dir \\ `; # correctly prints the root directory
其他命令似乎也能正常工作。
cd 从批处理文件的命令行运行良好。
还有其他人看过吗?有解决方法吗?
您可能正在寻找 chdir
。在反引号中使用 shell 命令不会产生持久的效果。当你 运行 一个反引号命令时,你会产生一个新的 shell,执行命令,然后 return 标准输出到 Perl。然后 shell 退出,对它的所有更改都将丢失。
I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
In the strictest sense, it can't be done--the script executes as a different process from the shell it was started from. Changes to a process are not reflected in its parent--only in any children created after the change.
我在 win7 上使用 AS perl。
print `cd \\ `; # does nothing, says nothing
同 qx()
print `dir \\ `; # correctly prints the root directory
其他命令似乎也能正常工作。
cd 从批处理文件的命令行运行良好。
还有其他人看过吗?有解决方法吗?
您可能正在寻找 chdir
。在反引号中使用 shell 命令不会产生持久的效果。当你 运行 一个反引号命令时,你会产生一个新的 shell,执行命令,然后 return 标准输出到 Perl。然后 shell 退出,对它的所有更改都将丢失。
I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
In the strictest sense, it can't be done--the script executes as a different process from the shell it was started from. Changes to a process are not reflected in its parent--only in any children created after the change.