How to make this makefile (4) rule in ant (1)?

I would like to know how to do something in ant (1), which is equivalent to the makefile (4) rule. The makefile (4) rule does the following: 1) starts a process that does not end and which writes one line to its standard output stream; 2) reads the line from the process; 3) creates a file using a string; and 4) it starts a second process that does not interrupt the use of the file as an argument. Schematically rule makefile (4)

program1 | while read arg; do \ echo $$arg >file; \ program2 file; \ done 

NOTE: "program1" writes one line; neither "program1" nor "program2" end.

How can this be done in ant (1)?

+4
source share
1 answer

You can use ProcessBuilder as described below:

 import java.io.BufferedReader; import java.io.InputStreamReader; public class PBTest { public static void main(String[] args) { ProcessBuilder pb = new ProcessBuilder("process1"); pb.redirectErrorStream(true); try { Process p = pb.start(); String s; // read from the process combined stdout & stderr BufferedReader stdout = new BufferedReader ( new InputStreamReader(p.getInputStream())); if ((s = stdout.readLine()) != null) { ProcessBuilder pb2 = new ProcessBuilder("process2", s); pb2.start(); ... } System.out.println("Exit value: " + p.waitFor()); p.getInputStream().close(); p.getOutputStream().close(); p.getErrorStream().close(); } catch (Exception ex) { ex.printStackTrace(); } } } 

Then your java task is pretty simple:

 <!-- Run the program --> <target name="run"> <java classname="PBTest" fork="true"></java> </target> 

Application:

I am looking for a solution in ant (1), not in Java.

You can use any supported Apache BSF or JSR 223 language in the script task . I don’t see the possibility of using standard input and output directly, but you can use loadfile task to load properties from a file. Here is an example that gets the version number from the source file.

+1
source

Source: https://habr.com/ru/post/1314454/


All Articles