I wrote a program that works with a text file and should send it by email. I used curl to send by email. I call curl from the program using the WinExec() API function WinExec() program works correctly when I start it from IDE (Codeblocks), everything is called, sending by email goes, but when I just launch it not from ide, sending email does not occur. It seems to me that the problem is that the IDE calls the console for a few seconds and allows curl `to bring there all that is necessary, and when I run the program manually, the console is not called (it prevents me) Output to the console when I run from IDE: Curl output

How can I do this in order to give time to execute curl and so that the program does not call the console for a long time, or if it did, so that it disappears faster, letting all commands execute? Approximate program code:

 #include <windows.h> #include <direct.h> #include <stdio.h> #include <string.h> int main(void){ char current_work_dir[700]; char clonedir[250]; char clonedir3[250]; strcat(clonedir3,"\""); _getcwd(current_work_dir, sizeof(current_work_dir)); _getcwd(clonedir, sizeof(clonedir)); strcat(clonedir3,clonedir); strcat(clonedir3,"\\bin\\Debug\\mail.txt\" -k --anyauth"); printf("%s",current_work_dir); strcat(current_work_dir,"\\curl smtp://smtp.gmail.com:587 -v --mail-from \"andybelous2@gmail.com\" --mail-rcpt \"andybelous2@gmail.com\" --ssl -u andybelous2@gmail.com:ПАСВОРД Я ПИШУ -T "); strcat(current_work_dir,clonedir3); WinExec(current_work_dir, SW_HIDE); Sleep(10000); return 0; } 
  • one
    I had a similar task ... In general, I spat, I took the curl library and just embedded the code I needed in the program ... - Harry
  • Sishnyh libraries for sending mail - cars. For Windows, there is certainly no point in using external utilities (especially since it creates an extra and unnecessary dependency for the program). - PinkTux
  • @PinkTux I don't know anything about sockets, protocols, etc., the program is straightforward and it would be much easier for me to use curl - andybelous2

1 answer 1

I found a mistake. The thing is that the _getcwd () function at launch from the IDE produced an incomplete file path, so I had to manually finish the \\bin\\Debug . When started manually, the function returned the full path, already with \\bin\\Debug and the command was not executed. For me, there is still a riddle, as it can be, because the IDE, in theory, runs the same file as me.

  • Oh, somewhere I have already seen this horrible code today. Read my comment there. Also, take a book of some kind or an intelligible guide to working with libraries in C. - 0andriy