I have an awk script which filters the file contents and i want that awk script to be called from java file.How to do ?

没有正确的解决方案

其他提示

Try Runtime.getRuntime().exec("/path/to/your/awk_script")

Take a look to Class Runtime

I had to support some script commands via a remote console interface, it was relatively straightforward, if tedious. The process will be the same with most apps running a script file such as an awk script.

I was having trouble, until I started using an approach based on this posting.

The main issue will not be what to do to fire the script, it is how to manage the output stream and stderr. That design decision will depend on your use case. You my just toss output away or store the "interesting" parts, whatever.

Again, depending on your circumstances it might be better to open a pipe between your awk script and your java program. You will get exactly the same results (more or less) with somewhat less hassle and some additional flexibility.

Finally I don't really understand the comment about using exec above. An exec function is an operating system call, just like opening a file. Overheads will depend on the o/s. Again though if it is a long-lived partnership consider the use of a pipe to tie them together. Good luck.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top