Ricardo Neves
Ricardo Neves

Reputation: 515

c++ wait for system call

I am working with files in C++. I call a program on system prompt to create a txt file. Then I use C++ to read that file. I need to make sure C++ wait for the program to finish before read the file.

An explanation C++:

createOutputFile(); 
system("Start wp/PRO386W.EXE /V1 consult('wp/read.pl').");
// I need to wait for this "PRO386W.EXE to finish
readLista();//before calling this method

Upvotes: 2

Views: 7784

Answers (3)

MaD
MaD

Reputation: 880

You can always check for end of file. Assuming fin is of type ifstream then you can check f (!fin.eof( ))

Upvotes: -4

JHumphrey
JHumphrey

Reputation: 999

system() waits for the command to complete. In your case, the "command" is "start" and that forces it to the background. Remove the "start" and you should be fine. If you really need for it to be asynchronous, you'll need to launch the process differently.

Upvotes: 7

Anton Kovalenko
Anton Kovalenko

Reputation: 21507

If the program WP/PRO386W.exe is a console program, just remove Start, which makes the program run in background. UPD: maybe you'll have to use backslash: "WP\\PRO386W.exe ...".

Upvotes: 1

Related Questions