How can I run a Ruby script from command line and get the response using Java code? -
i need run ruby script using command line java code.
for example file in path d:/myproject/myruby.rb
i want run file command line , response that. how can achieve this?
also, how can return response in myruby.rb caught in command line.
you can use this:
string[] commands = {"ruby","d:/myproject/myruby.rb"}; runtime rt = runtime.getruntime(); process proc; try { proc = rt.exec(commands); bufferedreader stdinput = new bufferedreader(new inputstreamreader(proc.getinputstream())); string s; while ((s = stdinput.readline()) != null) { system.out.println(s); } } catch (ioexception e) { e.printstacktrace(); }
Comments
Post a Comment