Results 1 to 15 of 15
  1. #1
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default How to run PHP and cmd in Java Desktop Programming?

    how to runs php in java desktop programming?
    what I mean is like when I runs my desktop programme, it's automatically runs my automatic script (php) as the background process of this java desktop.

    is it possible?
    how about to run .bat file too from java? thanks palz

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Desktop.open or Runtime.exec for the .bat file.
    Running the php file requires you to pass it through your PHP engine.

  3. #3
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    running .bat really gives result (thanks)
    running .php any keywords for this?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You could just make an HTTPConnection connection to the URL serving the script.

  5. #5
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    For the .bat, I use this code :
    public class ThisIsATest {

    public static void main(final String[] args) {
    try {
    Desktop.getDesktop().open(new File("example.bat"));
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    }
    For .php, I still not found the answer
    I use this code :
    URL u = new URL ("http://localhost:80/ThisIsATest/");
    URLConnection urlCon = servletUrl.openConnection();
    urlCon.setDoInput(true);
    con.setRequestMethod("GET");
    ObjectInputStream in = new ObjectInputStream(urlCon.getInputStream());
    in.close();
    urlCon = null;
    error everywhere

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You would have to supply the path to the .php file being served.
    I can't help with the errors you are getting because I don't know them. You would also need to do a little reading to find out how those classes work.

  7. #7
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by sysout View Post
    error everywhere
    error notified by your IDE before running or Exceptions thrown while running? what do they say?

  8. #8
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    Quote Originally Posted by atom86 View Post
    error notified by your IDE before running or Exceptions thrown while running? what do they say?
    how about using PHP-JAVA bridge?
    but the example is just about using java in php, no solutions for php in java :(

  9. #9
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    I don't know exactly what you meant to do... i can tell you that if you want only to visualize a .php page in a browser you could easily call
    Java Code:
    Desktop desktop = Desktop.getDesktop();
    desktop.browse("http[...]yourPage.php");
    else, if you are trying to create an application with an architecture

    client --> server/JCBC --> MySQL (or any DB server)

    i suggest you to operate in J2EE...

    that's the only things i can tell you.. i have no idea of how to create a bridge between PHP and Java..:(

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by sysout View Post
    ... no solutions for php in java :(
    Which of my responses did you not understand?

  11. #11
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    79
    Rep Power
    0

    Default

    how to runs php in java desktop programming?
    I understand php to run on a server. Is your java desktop programming associated with a server? I hope I read your post correctly.

    Menre

  12. #12
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    I have a .php script (which is refresh every 2 seconds to execute my script -> no print at all), so I want this script to runs in background.

    Which I want is, everytime I runs my desktop programming (java), both of those script (cmd and php) runs automatically in background, the cmd runs successfully (thanks to : r035198x), but .php hasn't succeed

  13. #13
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    79
    Rep Power
    0

    Default

    Hello,

    It is possible to put a PHP script into some markup languages, eg HTML Or work with it through Ajax/Javascript, etc. However, if you save a PHP script/file with the extension .php as you have done in your case now, you would then need to let it run on a server and perhaps reference it from another program after it has been process by the server.

    I have a .php script (which is refresh every 2 seconds to execute my script -> no print at all), ...
    You mentioned no print at all. Now, I would suggest that you first test that .php file alone on a server to see that it prints and is working correctly. After doing that, I suggest that you try it with your java application as someone has already mentioned before. That is, you reference it from you program.

    desktop.browse("http[...]yourPage.php");
    To bridge this Java-PHP application of yours, I would expect a server to be involved as PHP is a server scripting language.

    Hope this has helped so far.

    Menre

  14. #14
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    Java Code:
    import java.awt.Desktop;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author admin
     */
    public class PHPbrowser {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            Desktop.browse("http://localhost/phpFolder/");        
        }
    
    }
    this is my code, palz
    error on Desktop.browse("http://localhost/phpFolder/");

    error :
    run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
    at PHPbrowser.main(PHPbrowser.java:20)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)
    Last edited by sysout; 10-17-2009 at 02:16 PM.

  15. #15
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    Solved palz,,..thanks to all of you :)

    Here's the code which is work for me :
    Java Code:
    import java.awt.Desktop;
    import java.net.URI;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author admin
     */
    public class PHPbrowser {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            try {
                if (Desktop.isDesktopSupported()) {
                    Desktop desktop = Desktop.getDesktop();
                        if (desktop.isSupported(Desktop.Action.BROWSE)) {
                        desktop.browse(new URI("http://localhost/phpFolder"));
                    }
                }
            } catch (Exception e) {
                    e.printStackTrace();
            }
        }
    
    }
    Really appreciate your help.
    thanks for your hands


    but how to runs this as a background? it's automatically call for the default browser
    Last edited by sysout; 10-17-2009 at 02:22 PM.

Similar Threads

  1. Replies: 0
    Last Post: 08-18-2009, 05:50 PM
  2. Replies: 1
    Last Post: 12-02-2008, 09:48 AM
  3. learn java desktop database programming
    By scchia in forum JDBC
    Replies: 0
    Last Post: 07-21-2008, 06:12 PM
  4. Desktop search in java
    By hellosubs in forum New To Java
    Replies: 0
    Last Post: 06-15-2008, 04:33 PM
  5. Installer for Java desktop application
    By nitingupta183 in forum SWT / JFace
    Replies: 0
    Last Post: 03-18-2008, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •