i want call python
script java. python version 2.5 , java 6.
my current code:
try{ process p= runtime.getruntime().exec("path/dirs/file.py"); p.waitfor(); } catch (interruptedexception ex){ system.out.println(ex.getmessage());} }
the error receive is:
java.io.ioexception: cannot run program filename: createprocess error = 193, %1 not valid win32 application
try use precessbuilder
-
try{ string prg = "import sys\nprint int(sys.argv[1])+int(sys.argv[2])\n"; bufferedwriter out = new bufferedwriter(new filewriter("test1.py")); out.write(prg); out.close(); int number1 = 10; int number2 = 32; processbuilder pb = new processbuilder("python","test1.py",""+number1,""+number2); process p = pb.start(); bufferedreader in = new bufferedreader(new inputstreamreader(p.getinputstream())); int ret = new integer(in.readline()).intvalue(); system.out.println("value : "+ret); }catch(exception e){system.out.println(e);}
see here more detail.
Comments
Post a Comment