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

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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).

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.