开发者

Why can't Perl launch telnet under Windows?

开发者 https://www.devze.com 2022-12-14 02:53 出处:网络
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\')\"

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:\wi开发者_C百科ndows\system32, no special finding.

Could anybody help me on this case? Thanks a lot!


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


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.


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.


On my computer following code works (Windows 7):

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


It must be either a) permissions b) incorrect path, c) you need .exe at the end or d) you need to capitalise the "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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号