为什么Perl系统调用无法调用内部Windows命令? [英] Why is Perl system call failing to invoke internal Windows command?

查看:436
本文介绍了为什么Perl系统调用无法调用内部Windows命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的Windows XP计算机上,Perl系统命令如 dir / b 会生成一个错误消息,例如: / b:no such文件或目录。换句话说,开关被解释为文件名。

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. In other words, the switch is being interpreted as a filename.

这是因为我使用 backticks open() system()。我甚至尝试传递作为一个单独的arg到system()的开关。当然,我已经确认调用在DOS命令行或批处理脚本上正确工作。

This occurs whether I use backticks, open() or system(). I even tried passing in the switch as a separate arg to system(). Naturally, I have confirmed that the call works correctly on the DOS command line or batch script.

有人遇到过这个吗?

推荐答案

安装和 dir.exe 是在您的路径,它不是 cmd.exe 内置但是别名为 ls

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.

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`"
…

这篇关于为什么Perl系统调用无法调用内部Windows命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆