开发者

get the data from batch file to java program

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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜