在我们的一台 Windows XP 机器上,dir/b
等 Perl 系统命令会生成一条错误消息,例如:/b: no such file or directory
。换句话说,开关被解释为文件名。
无论我使用 backticks
、open()
还是 system()
都会发生这种情况。我什至尝试将开关作为单独的参数传递给 system()。当然,我已经确认调用在 DOS 命令行或批处理脚本上正常工作。
有没有人遇到过这个?
最佳答案
您可能安装了 Cygwin 并且 dir.exe
在你的路径中,这不是 cmd.exe
内置但是 ls
的别名.
C:\> which dir /usr/bin/dir C:\> c:\opt\cygwin\bin\dir.exe --version dir (GNU coreutils) 8.15 Packaged by Cygwin (8.15-1) … C:\> dir /b … C:\> perl -e "print `dir /b`" dir: cannot access /b: No such file or directory C:\> perl -e "print `cmd /c dir /b`" …
关于windows - 为什么 Perl 系统调用无法调用内部 Windows 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10119108/