简体   繁体   中英

Why can't Perl launch telnet under Windows?

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!

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.

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

您好,您使用的是Perl,所以我想知道为什么您不使用Net :: Telnet,而不是Windows的telnet.exe,而AFAIK并不适合于Windows。

On my computer following code works (Windows 7):

$telnet = $ENV{'WINDIR'} . '\system32\telnet.exe';
system("$telnet 192.168.1.1");

它必须是a)权限b)错误的路径,c)最后需要.exe或d)您需要大写“ c:”

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!

Read about console host .

ConHost represents a permanent change in the way that console application I/O is handled.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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