2013-07-02 2 views
0

다른 파일의 값을 출력하고 내 C++ 응용 프로그램에서 해당 값을 읽는 matlab 파일을 실행하려고합니다. 내 코드 :CreateProcess에 의해 생성 된 파일을 읽으려면 어떻게해야합니까?

int disponibilitate; 
STARTUPINFO si; 
PROCESS_INFORMATION pi; 

ZeroMemory(&si, sizeof(si)); 
si.cb = sizeof(si); 
ZeroMemory(&pi, sizeof(pi)); 

LPTSTR szCmdline = _wcsdup(TEXT("\"D:\\Program Files\\Matlab\\bin\\matlab.exe\" -nodisplay -nosplash -nodesktop -r \"run('C:\\Users\\Lucian\\Desktop\\licenta visual studio\\licenta\\licenta\\simulare.m');exit;\"")); 

if(!CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 

{ 
    printf("CreateProcess failed (%d).\n", GetLastError()); 
    return; 
} 
    fin.open("simulare_matlab_out.txt"); 
    fin>>disponibilitate; 
    cout<<disponibilitate; 
fin.close(); 
CloseHandle(pi.hProcess); 
CloseHandle(pi.hThread); 

simulare_matlab_out.txt는 내 MATLAB 응용 프로그램의 출력 파일입니다. C++ 프로젝트를 실행 한 후 임의 값을 인쇄하지만 simulare_matlab_out.txt 파일에서 값은 올 바르며.

!!! 내 문제는 프로그램이 생성 된 프로세스가 끝나고 생성 된 파일을 읽을 때까지 기다리지 않는다는 것입니다! 도움이 필요하십니까?

답변

0

STDOUT을 사용하십시오.

http://www.cplusplus.com/reference/cstdio/stdout/

파일 * 스트림; if ((stream = freopen ("file.txt", "w", stdout)) == NULL) exit (-1);

printf ("this is stdout output \ n");

stream = freopen ("CON", "w", stdout);

printf ("이제 다시 콘솔로 돌아갑니다. \ n");

+0

은 파일 작성시 표준이 아닙니까? –

+0

제 생각에는 프로그램이 생성 된 프로세스가 끝나고 생성 된 파일을 읽을 때까지 기다리지 않는다고 생각합니다. –

관련 문제