简体   繁体   English

为什么Perl系统调用无法调用内部Windows命令?

[英]Why is Perl system call failing to invoke internal Windows command?

On one of our Windows XP machines, Perl system commands such as dir /b generate an error message such as: /b: no such file or directory . 在我们的一台Windows XP计算机上,Perl系统命令(例如dir /b生成错误消息,例如: /b: no such file or directory In other words, the switch is being interpreted as a filename. 换句话说,该开关被解释为文件名。

This occurs whether I use backticks , open() or system() . 无论我使用backticksopen()还是system() ,都会发生这种情况。 I even tried passing in the switch as a separate arg to system(). 我什至尝试将开关作为单独的arg传递给system()。 Naturally, I have confirmed that the call works correctly on the DOS command line or batch script. 自然,我已经确认该调用可以在DOS命令行或批处理脚本上正常工作。

Has anybody else encountered this? 还有其他人遇到过吗?

You probably have Cygwin installed and dir.exe is in your path which is not the cmd.exe built-in but an alias to ls . 您可能已经安装了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`"
…

Unverified: 未验证:

dir is a command interpreter built-in command. dir是命令解释器的内置命令。 Run the command interpreter with a /c or /k switch instead, followed by the command you want to execute. 而是使用/c/k开关运行命令解释器,然后运行要执行的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM