Java Execute External Program
Posted By admin On 28/10/19- Java Execute External Program In Windows 7
- Java Call External Program
- Java Execute External Program In Firefox
Apr 04, 2016 Friends its very simple. Import os module and run os.system(command) 2. Import subprocess and run subprocess.Popen. I'm trying to execute an external program with Java using ProcessBuilder, but it expects input from the user. To be more specific, the program is PGSQL (Postgres SQL), when it's executed the program. The above Java’s code will try to execute the external program (helloworld.exe) and show output in console as exit code of the external program. The sample external program, Helloworld.exe (Visual Basic) Code Explanation. Windows: execute something in Program Files We want to execute the textpad editor located in C:Program FilesTextPad 4 but without hard coding the path since it can be different for a localized version of Windows. We simply extract to environnment variable called%programfiles% and build the complete path from there.
I'm trying to execute an external program with Java using ProcessBuilder, but it expects input from the user.
To be more specific, the program is PGSQL (Postgres SQL), when it's executed the program prompts the user for a password. The only way to bypass that is to save a file in the user home containing the passwords, I'm trying to avoid that, so I want to execute the program from Java and send the password using the process' output stream.
The code works fine when the program doesn't expect any user input, but when I delete the password file from the user home, the program hangs. I see that it's being executed, but nothing happens. If I debug it, it reaches the while and then nothing happens until I kill the process.
This is the code, any help will be greatly appreciated.
Thanks a lot.
This game teaches you how to reason in the binary system! Indicate the right bits to get to the indicated number, or if the bits are indicated, select the right number on the right. Clear the whole board and have fun with this game made by Cisco! Embed this game. Learn Python with Penjee Binary Calculator Why do computers use binary? Cisco Binary Number Game. Sort Detective. Game not working? © 2010-2019 MrGober.com. I wrote the code myself with Code.org. This is taking longer than usual. Try reloading the page. Fun binary games.
2 Answers
I believe the prompt is going to STDERR, not STDOUT, so you'll have to open a stream connected to that and read there. When you try to read from STDOUT your code hangs waiting for output that will never arrive.
EDIT: I see you have redirected the error stream in the ProcessBuilder.
One other possibility is that the BufferedReader is waiting for a newline to finish reading, and the prompt does not end with a newline.
Jim GarrisonJim GarrisonBeen a long time, but got exactly the same problem. Here is a SSCCE that should work:
remiremiJava Execute External Program In Windows 7
Java Call External Program
