0

i want to read the data from the batch file to java program. my java program is calling the batch file & it is giving the output for following command

C:>FIND "check" d:\c.txt

---------- D:\C.TXT check

i want to read this "check" in my java program.

Thanks, Murali

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
krishna
  • 97
  • 2
  • 4
  • 6

3 Answers3

1

You haven't shown us how do you execute this batch. If you use Runtime.exec() then have a look at this example of capturing output: http://www.rgagnon.com/javadetails/java-0014.html

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
0

You can redirect the output of the FIND command to a dynamically named file and have it read by Java.

C:\FIND "check" d:\c.txt > yourUniqueFileName.txt

Then read the file yourUniqueFileName.text, parse and delete on the end (or not).

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
0

You can use ProcessBuilder or Process to exec() and then capture the output. More info here. You could redirect to a file and then read the file - however you're at the mercy of diskspace/permissioning issues, plus you should uniquely name your file etc.

Note that you'll need to be careful when capturing output from a spawned process. See this answer for more details.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440