• Post Reply Bookmark Topic Watch Topic
  • New Topic

Send data to the terminal via Java program  RSS feed

 
maxime trompier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!