• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running executables - one works; one doesn't

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Googled, did a search on this site and read nice article www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html, but still didn't find anything that helps.

Problem: Trying to run Remote Desktop and Telnet by using Runtime.getRuntime().exec().
Results:
Running Remote Desktop works.
Running Telnet generates a "java.io.IOException: Cannot run program "C:\Windows\System32\telnet.exe": CreateProcess error=2, The system cannot find the file specified"

Facts;
telnet.exe and mstsc.exe both exist in C:/Windows/System32.
To spawn Remote Desktop, the string passed into the method below is "mstsc.exe /f /v:", "ip_address" set to the IP address of the system and "additional" is empty.
To spawn Telnet, the string passed into the method below is "telnet.exe ", "ip_address" set to the IP address of the system and "additional" is the port desired.
"telnet.exe ip_address port" works from a command line window and from the start dialog.
Both applications have the same permissions.

Any help appreciated...

Code used:
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lori Cook wrote:
To spawn Remote Desktop, the string passed into the method below is "mstsc.exe /f /v:", "ip_address" set to the IP address of the system and "additional" is empty.
To spawn Telnet, the string passed into the method below is "telnet.exe ", "ip_address" set to the IP address of the system and "additional" is the port desired.


In cases like this you need to look for even the slightest difference. See the text that I've made bold above.
Print the value of prog.toString() and the problem should become clear.
 
Lori Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Printed out the buffer for the two invocations. The IP address/port removed to protect the innocent. Quotes added around the copy/paste of data.

Telnet invocation: "telnet.exe <address> <port>"
Remote desktop invocation: "mstsc.exe /f /v:<address>"

Took the telnet invocation and pasted into the Search programs and files field of the Start menu and...Got a telnet window/connection.

So...blanks are in the proper place for both invocations. One requires a port, hence the additional field. And either invocation pasted into the Search programs and files field works.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lori Cook wrote:Printed out the buffer for the two invocations. The IP address/port removed to protect the innocent. Quotes added around the copy/paste of data.

Telnet invocation: "telnet.exe <address> <port>"
Remote desktop invocation: "mstsc.exe /f /v:<address>"

Took the telnet invocation and pasted into the Search programs and files field of the Start menu and...Got a telnet window/connection.

So...blanks are in the proper place for both invocations. One requires a port, hence the additional field. And either invocation pasted into the Search programs and files field works.




Perhaps it would be a good idea to use the version of the exec() method that takes a string array, instead of a string? This way, you don't have to worry about the "blanks are in the proper place", or if it is being parsed correctly.

Henry
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lori Cook wrote:So...blanks are in the proper place for both invocations.


Well your code doesn't add a space between the address and port in your telnet command, so presumably you've included a space either at the end of the ip_address parameter or at the start of the additional parameter.
Relying on the calling code to remember to add that space is always a bad idea. Far better to get your method code to do it or, even better, follow Henry's advice.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lori Cook wrote:Any help appreciated...


Well, I hate to say (because you're probably not going to want to hear it), but running almost anything with Runtime.exec() is likely to be a kludge, because Java was never meant as a vehicle for running platform-based programs. Indeed, it goes against the whole ethos of the language.

If it's a requirement for a course, then obviously you must do it; but if it was me, I'd much rather use a library such as Apache Commons-Net.

Winston
 
Lori Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately the requirement is to spawn a separate process/application for the user. I might be able to mimic that with the Apache telnet classes, but don't want to re-invent the wheel when an application already exists.
 
Lori Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Final analysis - you cannot launch telnet within another program, batch file, etc. on Windows 7 (and Vista?). The Windows Security will not let you do it. You have to use some other application or interface to do telnet.

The only time you can run telnet is from within a Windows command window and/or from the Run field of the Startup Menu.
Sigh.

My solution - run a batch file that spawns off a PuTTY telnet session.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lori Cook wrote:Final analysis - you cannot launch telnet within another program, batch file, etc. on Windows 7 (and Vista?). The Windows Security will not let you do it. You have to use some other application or interface to do telnet.

The only time you can run telnet is from within a Windows command window and/or from the Run field of the Startup Menu.
Sigh.

My solution - run a batch file that spawns off a PuTTY telnet session.



You're all totally WRONG. ;)

You can launch tftp.exe but you have to use the secret path: c:\windows\sysnative\tftp.exe

You're welcome!
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
reply
    Bookmark Topic Watch Topic
  • New Topic