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
  • 549,808
  • 132
  • 1,049
  • 1,115
krishna
  • 99
  • 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
  • 50,951
  • 17
  • 64
  • 108
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ć
  • 60,971
  • 26
  • 119
  • 144
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
  • 261,477
  • 36
  • 323
  • 432