• 0

C++ Question


Question

here's the idea...

i made a program that launches a file in the main method...something like:

int main()

{

ShellExecute(hwnd, "open", "list.bat" , NULL,0, SW_MAXIMIZE); //create a text file of the song list;

...

}

this runs a batch file which creates a text file.

now, i want the program to access that text file created by this batch file while the program is still running. at the moment, what happens is that i have to run the program twice...1st to create the file, 2nd to access the file. what do i have to do in order to get this done in one process only??

someone suggested closing the text file created by the batch file. however, how am i supposed to do that since i haven't even assigned a variable name to the file until i use ifstream to open the file. maybe i have to close it through the batch file itself?

Please help...thanks.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

The first idea that comes to mind is not using a batch file; just create the file using C. But presumably you have some good reason for using batch files...

What you need to do then is to wait until the batch file finishes running; that way you can be assured that the file has been created and is no longer in use. To do this you need to use ShellExecuteEx (instead of ShellExecute) and the SEE_MASK_NOCLOSEPROCESS flag to get a handle to the batch process. Then wait on it using WaitForSingleObject.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.