views:

327

answers:

6

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!

+2  A: 

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.

catwalk
I also tried telnet.exe, not work either. What I'm doing is to show up a telnet console (like connected to a BBS), does Net::Telnet handle the screen rendering for me?
yongsun
@yongsun: no, you will have to handle screen printing on your own. As for `perl -e "system('c:\windows\system32\telnet.exe localhost')"` it works fine on my system (XP Pro)
catwalk
yeah, Windows XP is fine.
yongsun
A: 

It must be either a) permissions b) incorrect path, c) you need .exe at the end or d) you need to capitalise the "c:"

Richard
A: 

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!

tzup
I run the perl executable as an administrator, from a command console, from which I could launch telnet.exe successfully.And Windows XP does not have this issue.
yongsun
So if you run perl in cmd as admin it works? Then my guess would be to check group policies on that Win2008 box. (not sure what type of policy might disallow perl to run)
tzup
sorry, I mean from the cmd console, I could launch the telnet.exe directly, but failed to launch it from perl (on the same console).
yongsun
Can you launch Perl at all from cmd? (on the side, if you are using ActivePerl, you should use 5.8.8 or 5.10.0 releases - they are tested against Win2008)
tzup
yes, I can, and I'm using ActivePerl 5.8.8 ...
yongsun
A: 

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.

Sinan Ünür
Thanks for the info, I tried to launch wperl -e "system('c:\windows\system32\telnet localhost')" from "start->Run", still failed.
yongsun
+1  A: 

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.

+1  A: 

On my computer following code works (Windows 7):

$telnet = $ENV{'WINDIR'} . '\system32\telnet.exe';
system("$telnet 192.168.1.1");
n0rd
still failed to launch :(
yongsun
Strange, Windows 2008 and Windows 7 should have similar environments. What is printed if you run `perl -e "print -r $ENV{'WINDIR'} . '\system32\telnet.exe'"`?
n0rd