-2

I want to run a custom file test.exe. I tried ShellExecute() and system(), but it did not work. How could i fix this?

code:

#include <stdio.h>
#include <windows.h>
int main()
{
    system("C:\\Users\\user\\test.exe");
}

The code AND the next code system("PAUSE") is skipped and does not return or make error during running. I used errno code by answers and also does not treat the error. It probably has test.exe in that directory and when I researched, that format is right and worked well in others. It does not return anything, even -1 and shuts down. I did check the task manager to see the program test.exe running and printing the Hello World(which is the right thing), but there was nothing.

  • 1
    Does this answer your question? [How to run an exe using c prog](https://stackoverflow.com/questions/4705725/how-to-run-an-exe-using-c-prog) – max Nov 08 '20 at 13:01
  • When the functions fail to run the program, have you checked *why*? For example when [`ShellExecuteA`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea) fails have you checked what error it actually returns? And for [`system`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/system-wsystem?view=msvc-160) have you checked `errno`? – Some programmer dude Nov 08 '20 at 13:08
  • I used your comments to fix them, and first one I tried a lot of times, but it simply the system and shellexecute code does not run and left no return codes. – user14573927 Nov 09 '20 at 01:05
  • Both functions *return* a value. Have you checked this value? Like e.g. `if (system(...) == -1) { printf("Error running program: %s\n", strerror(errno)); }` – Some programmer dude Nov 09 '20 at 05:26
  • Or do you mean that neither function actually returns? Then the program *is* running. It's just running without a window you can see, or the window end up behind other windows. What is this `test.exe` program supposed to do? – Some programmer dude Nov 09 '20 at 05:28
  • sorry for chencking your answer late. neither function is returning and the program wasn't running though i was checking all process in task manager. text.exe is simple file printing Hello World for the testing. – user14573927 Nov 12 '20 at 02:54

1 Answers1

0

Try running system("open C:\\Users\\user\\test.exe"); works on linux and mac, and should work in windows

martiwg
  • 85
  • 10
  • for windows try changing the slashes between users and test.exe for a ```>``` – martiwg Nov 08 '20 at 13:05
  • Thanks for listening my question. I tried that way, changing the slashed and write open, but It still does not work however. I uses visual studio 2019. – user14573927 Nov 09 '20 at 01:02