Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Run Python file in Java code

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Run Python file in Java code

    Dear friends

    I want to run a Python executable file in Java
    In windows i installed Python and and execute this file easily in command line mode (this file accept some argument for its procedure)

    D:\pyhon27\python D:\python27\cp_wordnet.py 2 2 2 2r 2e 3ssd 2dfdf 2 1 2 2

    Now i want to do same thing in Java code, i means i should cal cmd and execute that line on that, i have already tried these commands
    (The 'path' is String and equal to "D:\pyhon27\python D:\python27\cp_wordnet.py 2 2 2 2r 2e 3ssd 2dfdf 2 1 2 2")
    Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+ path);
     
    Process p = Runtime.getRuntime().exec("cmd /c "+ path);
     
    Process p = Runtime.getRuntime().exec("rundll64 SHELL64.DLL,ShellExec_RunDLL "+ path);			
     
    Process p  = Runtime.getRuntime().exec(path);

    but i haven't had result !!


    could somebody pleas help me


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Run Python file in Java code

    What do you mean by "I haven't had result"? Are you getting errors/exceptions? Or is something else not working (like no console output)? Please post the problem in detail.

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Run Python file in Java code

    I mean ,there was nothing happen, no console display,not output file, no error,even no exception. it looks some second process happen and after that nothing Shall i use some other syntax to handle this !!

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Run Python file in Java code

    By default, Java doesn't pass it's standard streams to any processes it starts. You must manually obtain the handles for the standard streams of that process, then redirect them appropriately to your Java programs' standard streams.

Similar Threads

  1. Code for parsing .c file in java
    By Kakashi in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 5th, 2013, 11:51 PM
  2. File Reading code doesn't work
    By koryvandell in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2011, 08:40 AM
  3. Replies: 10
    Last Post: April 5th, 2011, 09:09 AM
  4. JDBC code not included into JAR file??
    By friday in forum JDBC & Databases
    Replies: 4
    Last Post: December 17th, 2010, 11:32 AM
  5. Java equivalent of Pythonís struct.pack?
    By thiruvadi.e in forum Java SE APIs
    Replies: 2
    Last Post: July 14th, 2010, 03:09 AM