为什么 Perl 在 Windows 下无法启动 telnet?
我在 Windows 2008 上启用了 telnet 客户端功能,并尝试从 Perl 脚本启动它:
perl -e "system('c:\windows\system32\telnet localhost')"
然后我收到如下错误:
'c:\windows\system32\telnet' is not recognized as an internal or external command,
operable program or batch file.
我可以从“cmd”终端运行它,或者,如果我将 telnet.exe 复制到本地目录,就可以启动了。我检查了c:\windows\system32下telnet.exe的权限,没有发现什么特别的情况。
有人可以帮我处理这个案子吗?多谢!
I had enabled telnet client feature on Windows 2008, and tried to launch it from a Perl script:
perl -e "system('c:\windows\system32\telnet localhost')"
Then I got an error like this:
'c:\windows\system32\telnet' is not recognized as an internal or external command,
operable program or batch file.
I could run it from 'cmd' terminal, or, if I copy the telnet.exe to local dir, it could be launched. I examined the permissions of telnet.exe under c:\windows\system32, no special finding.
Could anybody help me on this case? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我最近遇到了完全相同的问题,尝试以编程方式启动 telnet 和 rdp 客户端。该问题与 Windows“设计”的一个方面(称为文件系统重定向)有关:
“Windows 64 位 (WOW64) 上的 Windows 提供文件系统重定向。在 64 位版本的 Windows Server 2003 或 Windows XP 中,%WinDir %\System32 文件夹是为 64 位应用程序保留的。当 32 位应用程序尝试访问 System32 文件夹时,访问将重定向到以下文件夹:%WinDir%\SysWOW64 默认情况下,启用文件系统重定向。
http://www.codeproject .com/tips/55290/Disabling-Windows-file-system-redirection-on-a-CFi.aspx
I ran into the exact same problem recently, trying to launch telnet and the rdp client programmatically. The problem is related to an aspect of windows "design" called file system redirection:
"Windows on Windows 64-bit (WOW64) provides file system redirection. In a 64-bit version of Windows Server 2003 or of Windows XP, the %WinDir%\System32 folder is reserved for 64-bit applications. When a 32-bit application tries to access the System32 folder, access is redirected to the following folder: %WinDir%\SysWOW64. By default, file system redirection is enabled."
http://www.codeproject.com/tips/55290/Disabling-Windows-file-system-redirection-on-a-CFi.aspx
我认为你必须指定程序的全名,即
telnet.exe
。但你最好使用 Net::Telnet 模块或类似 Expect.pm 的东西,以编程方式处理交互式会话。I think you have to specify the full name of the program, that is
telnet.exe
. But you'd be better off using Net::Telnet module or something like Expect.pm that handles interactive sessions programmatically.你好,你使用的是Perl,所以我想知道为什么你不使用Net::Telnet,而不是Windows的telnet.exe,据我所知这对编程不友好。
hi you are using Perl, so i was wondering why you don't use Net::Telnet, instead of the telnet.exe of windows, which AFAIK is not friendly for programming.
在我的计算机上,以下代码有效(Windows 7):
On my computer following code works (Windows 7):
它必须是 a) 权限 b) 不正确的路径,c) 您需要在末尾添加 .exe 或 d) 您需要将“c:”大写
It must be either a) permissions b) incorrect path, c) you need .exe at the end or d) you need to capitalise the "c:"
您可能想要验证 Perl 在哪个帐户下执行,并检查该帐户是否有权运行 telnet 等可执行文件。
为了验证这个理论,我会在高权限帐户(例如 admin)下运行 Perl,以检查它是否运行 telnet,然后调整它运行的帐户。
希望这有帮助!
You might want to verify under what account Perl execute and check if that account has permissions to run executables like telnet.
Just to verify the theory, I'd run Perl under a high privileged account (like admin) to check if it runs telnet and then tweak the account it is running under.
Hope this helps!
了解
另请参阅SysInternals 论坛上的相关帖子。
我现在无法访问任何 Windows Server 2008 计算机,因此无法对此进行测试,但是您可以检查一下运行 wperl -e "system('c:\windows\system32\telnet localhost') 时会发生什么吗" 相当于 Start ->在该操作系统上运行。
Read about console host.
See also a related post on SysInternals forums.
I do not have access to any Windows Server 2008 machines right now, so I cannot test this, but can you check what happens when you run
wperl -e "system('c:\windows\system32\telnet localhost')"
from the equivalent of Start -> Run on that OS.答案是:使用sysnative而不是system32,因为32位应用程序不允许访问system32目录(64位应用程序)。通过使用这个别名 sysnative 就可以了。
The answer is: using sysnative instead of system32, because the 32-bits application is not allowed to have access to the system32 directory (64-bit application). By using this alias sysnative it wil work.