0

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.

7
  • 2
    use webservice for that. Commented Sep 7, 2016 at 17:04
  • AJAX is your friend here. Commented Sep 7, 2016 at 17:07
  • 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. Commented Sep 7, 2016 at 17:27
  • I think you will find the answer over here: stackoverflow.com/questions/12897070/… . Also, see docs.oracle.com/javase/7/docs/technotes/guides/scripting/… to see about how to pass vars into the script. Commented Sep 7, 2016 at 17:31
  • @Jamie that doesn't state how to get the data to Java or from Java to the script. Commented Sep 7, 2016 at 17:34

1 Answer 1

-1

That sounds like a terrible idea, but who am I to judge... You can try j-php http://j-php.net

In the other direction you can try http://php-java-bridge.sourceforge.net/pjb/index.php

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I know this sounds awfull, but I'm making a Java program and I need to use an API only available to Python and PHP. Are there any other options?