perl反引号不适用于cd.为什么?

use*_*305 -5 perl backticks

我在win7上使用AS perl.

print `cd \\\\ `; # does nothing, says nothing
Run Code Online (Sandbox Code Playgroud)

与qx()相同

print `dir \\\\ `;  # correctly prints the root directory
Run Code Online (Sandbox Code Playgroud)

其他命令似乎也运行正常.

cd从批处理文件的命令行正常工作.

有没有人见过这个?有解决方法吗?

TLP*_*TLP 7

你可能正在寻找chdir.在反引号中使用shell命令不会产生持久影响.当您运行反引号命令时,您生成一个新的shell,执行该命令,并将标准输出返回给Perl.然后shell退出,对它的任何和所有更改都将丢失.

  • @ user1067305不要将[Windows命令](https://technet.microsoft.com/en-us/library/bb490875.aspx)`chdir`与[Perl函数]混淆(http://perldoc.perl. org/functions/chdir.html)`chdir`.前者只会改变调用它的shell的工作目录; 后者将更改Perl脚本的工作目录. (5认同)