• 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

Send data to the terminal via Java program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am working on a project where at one point, I have to login to an external program from my java program.
To do so, I have implemented the following function:



This function successfully sends the "p4 login" function to the terminal, but apparently, the next command where I send the password does not work.
I know this because of the output I receive after the System.out.println(); Indeed, the output is always "Enter password", which is the anwser of the first command.

I have tried other stuff, such as :



but the result is always the same.

I guess the exec() function can only send standard commands to the terminal, so is there a way to send a normal string to it?

Thank you in advance
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The OutputStream should work. Note, however, that the process might use a non-standard way of obtaining user input, such as using console functions directly, so that the characters of the password as typed by the user would not be displayed on the console. In this case you cannot supply the password via the OutputStream of the process.

Can't you provide the password on the command line? It would probably be much easier and less error prone.
 
maxime trompier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right, the password entered by the user is not displayed on the console.
If the outputStream then does not work, what can I do?

Also, how could I send the password on the command line?
reply
    Bookmark Topic Watch Topic
  • New Topic