-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.

6
  • 1
    Does this answer your question? How to run an exe using c prog
    – max
    Nov 8, 2020 at 13:01
  • When the functions fail to run the program, have you checked why? For example when ShellExecuteA fails have you checked what error it actually returns? And for system have you checked errno? Nov 8, 2020 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. Nov 9, 2020 at 1: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)); } Nov 9, 2020 at 5: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? Nov 9, 2020 at 5:28

1 Answer 1

0

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

2
  • for windows try changing the slashes between users and test.exe for a >
    – martiwg
    Nov 8, 2020 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. Nov 9, 2020 at 1:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.