0

Iam using ShellExecute WIN API to run DOS command because DOS command flashes are seen when i run the application. Below is the ShellExecute API call.

ret = ShellExecute(0, "open", "cmd.exe", "/C ver > version.txt", 0, SW_HIDE);

After this I tried to open version.txt using fopen function but it is returning NULL.

Any help is appreciated.

mujtaba
  • 155
  • 10
  • Please close your question by clicking the checkmark to the left of the answer that helped you most. – bgoldst Mar 11 '15 at 12:47

1 Answers1

2

ShellExecute() runs the specified process asynchronously. The reason fopen() is failing is almost certainly that the cmd process has not had enough time to actually create the file.

There are a couple of ways to solve this. Probably the best one for your case is to instead use ShellExecuteEx() to retrieve the process handle in hProcess, which will allow you to wait for its termination before resuming your code. See How to wait for ShellExecute to run?.

Community
  • 1
  • 1
bgoldst
  • 30,505
  • 4
  • 34
  • 59