I'm trying to open a console and run a PHP script, but after running it I need to print stuff to the console to get data from my Java program to the script, and the other way around.
I know there are already questions on here that ask kinda the same thing, but they don't mention how to get variables from the program to the script.
I strongly recommend to make an API written on PHP and make calls from java application to php application in order to get your data. You just need to understand, that having to separate applications that communicate with each other is normal, but running php scripts directly from java - is not.
You could also use IPC (inter process communication).
Also, if the PHP or Python application has an output that you need on your java application you could save it in a file or in a database and read it from Java. Difficult to say without knowing more about the use case.