Reputation: 235
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.
Upvotes: 0
Views: 373
Reputation: 35324
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?.
Upvotes: 2