파일에서 로그를 인쇄하려면 다음 코드를 사용했지만 "System.out.println"문을 인쇄 할 수 없습니다. 배치 파일 코드에 존재합니다.일괄 파일 캡처 명령 프롬프트 로그를 실행하고 해당 로그의 백업을 Java를 사용하여 파일에 저장하십시오.
Runtime runtime = Runtime.getRuntime();
Process p1 = runtime.exec("C:\\Users\\mf11131\\Desktop\\Batch\\SimpleBatch.bat");
java.io.InputStream is = (java.io.InputStream) p1.getInputStream();
File logfile = new File("C:\\logs\\Logfile.txt");
FileOutputStream fop = new FileOutputStream(logfile);
int i = 0;
while((i = is.read()) != -1)
{
fop.write((char)i);
}
다음은 배치 파일의 간단한 코드입니다.
class abc
{
public static void main(String args[])
{
int count=0;
for(int i=0;i<10;i++)
{
System.out.println("hi hello"+count);
}
}
}
배치 파일 코드를 게시하고 정확히 원하는 출력이 로그 파일에 있는지 확인하십시오. – XtremeBaumer
그런 'BAT' 파일과 같이 작동하지 않을 것이라고 생각합니다. – Antoniossss
"SimpleBatch.bat"파일의 내용은 무엇입니까? SimpleBatch.java를 제공했습니다. –