Results 1 to 4 of 4
  1. #1
    cool is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default calling python file from java

    Hi,
    I am writing a code which will call a python file from java as follows :


    String test ="python agent.py"+" backup";
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(test);


    backup is argument passed to agent.py.

    but its not working... can anybody help...????

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Is there no space between .py and backup? Check the API for how to call exec. You will want to add a space or use an array of Strings. Also, you may need to swallow the streams that the process produces.

    Edit: ignore the issue about space, since on re-read, I see you have one. Still if I were you I'd gobble the Streams produced by the process and even print them out. Perhaps the python code is producing an error and you're not seeing it, or perhaps your OS's buffers are so small that a small Stream is filling it and blocking it.
    Last edited by Fubarable; 11-10-2010 at 03:59 PM.

  3. #3
    cool is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    Thanks Fubarable. Its working fine nw... :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Problem with calling php script from java file
    By eldushyant in forum Advanced Java
    Replies: 1
    Last Post: 04-28-2010, 01:56 PM
  2. Jython : python for java
    By cotarelo in forum New To Java
    Replies: 1
    Last Post: 03-25-2010, 09:53 AM
  3. calling a jar file from within java application
    By robby14 in forum Advanced Java
    Replies: 3
    Last Post: 03-10-2010, 09:11 PM
  4. excecuting a jar file by calling a java class
    By Lavanya.vitria in forum Advanced Java
    Replies: 1
    Last Post: 12-13-2008, 01:11 PM
  5. Calling Java methods form Python
    By mew in forum Advanced Java
    Replies: 1
    Last Post: 12-21-2007, 03:30 PM

Posting Permissions

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