I have a small piece of C code as below. I have tried to run it using 2 methods.
1) With Clion using Cygwin64 environment
2) With command prompt (in this case, I have to move a cygwin1.dll to the same folder with the executable).
My code need to call the system() function to run some cmd command.
If i tried the 1st method, the code works flawlessly. However, when using the 2nd method, the system() call seems to be doing exactly nothing.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
FILE *fp=fopen("run.bat", "w+");
fprintf(fp,"dir > result.txt\n");
fclose(fp);
printf("Before calling System\n");
system("cmd.exe /c run.bat");
if(access("result.txt",F_OK)==0){
printf("Run completed!\n");
}
printf("After calling System\n");
}
What I get for doing with 1 is the line "Run completed!" got printed out normally.
However, with 2, no "result.txt" was created, and thus the "Run completed!" line never appears.
Now I need my executable to be executable in cmd to be of any use. So can anyone help?